问题描述
我有一个库 Eclipse 项目/工作区,其中包含偶尔交付给客户的功能.我们都是研究人员,所以这是非常非正式的;我制作了一个 JAR 和一个带有文档的 Word 文件,然后发送给他们.
I have a library Eclipse project/workspace containing functionality that is occasionally delivered to a customer. We're all researchers so this is done very informally; I make a JAR and a Word file with documentation, and send it to them.
我更喜欢向他们发送一个只包含他们实际需要的 JAR 文件,以简化事情.如果他们需要 X、Y、Z 和 W 类,那么我会发送一个 JAR 文件,其中包含 X、Y、Z 和 W 以及它们所依赖的所有类.
I prefer to send them a JAR file that only contains what they actually need, to simplify things. If they need classes X, Y, Z and W, then I send a JAR file containing X, Y, Z, and W, as well as all of the classes that those depend on.
现在我正在以无可救药的手动方式执行此操作(我创建一个新项目,拖过 X、Y、Z 和 W,然后拖过我需要修复编译器错误的任何内容).在 Eclipse 中自动化的正确方法是什么?
Right now I am doing this in a hopelessly manual way (I create a new project, drag over X, Y, Z, and W, and then drag over anything I need to fix the compiler errors). What's the right way to automate it in Eclipse?
为了清楚起见,所涉及的 Eclipse 项目包含的类比客户实际需要的多得多.
Just to be clear, the Eclipse projects involved contain many more classes than are actually needed by the customer.
另外,不涉及反射;我可以确信编译器知道发生了什么.我是编写代码的人,我避免像瘟疫一样进行反思.我使用反射的唯一地方是模仿 Collections.toArray(),在这种情况下,唯一可能导致问题的类是用户提供的类.
Also, there is no reflection involved; I can be confident that the compiler knows what is going on. I'm the one who wrote the code, and I avoid reflection like the plague. The only place I used reflection is to imitate Collections.toArray(), and in that case the only class that could cause a problem is one that the user provided.
推荐答案
Byecycle,一个 Eclipse 插件会有所帮助,但它已从 Sourceforge 中删除.不是在获得一个彻底的自动化过程,而是在确定依赖关系.我不确定你是否可以让它在 Ganymede/Galileo 上工作,因为我很久以前就使用过它.
Byecycle, an Eclipse plugin would help, but it has been removed from Sourceforge. Not in getting a thorough automated process, but in determining the dependencies. I'm not sure whether you can get it to work on Ganymede/Galileo, since I've used this a long time back.
更新
类依赖分析器工具可能会更有帮助,因为它带有一个插件-in 扩展 API,可用于创建插件以准确执行您打算执行的任务.
The Class Dependency Analyzer Tool might prove to be more helpful, since it comes with a plug-in extension API that could be used to create a plug-in to perform exactly the task that you intend to do.
更新 #2
如果您想知道 Ant 的用法,您可以使用 ClassFileSet 类型来获取一个类及其依赖项列表.这可以在复制任务中引用以复制所需的类文件.请注意,这不会复制源文件.
In case you were wondering about the usage of Ant, you can use the ClassFileSet type to obtain a class and its list of dependencies. This can be referenced inside a copy task to copy the required class files. Do note that this doesn't copy source files.
在内部,此方法依赖于 BCEL 库,因此如果您希望执行复制对于源代码,您可以尝试编写代码来检查 .class 文件的依赖关系,并将源代码复制到另一个目录.
Internally, this method depends on the BCEL library, so if you wish to perform a copy of sources, you could attempt to write code to examine a .class file's dependencies, and copy the sources over to another directory.
这篇关于根据一个源文件的依赖关系创建 Java Eclipse 项目的子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!