Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a subset of a Java Eclipse project based on dependencies of one source file

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.

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.

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?

EDIT: Just to be clear, the Eclipse projects involved contain many more classes than are actually needed by the customer.

EDIT: 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.

like image 373
jprete Avatar asked Dec 29 '22 16:12

jprete


1 Answers

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.

Update

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.

Update #2

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.

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.

like image 69
Vineet Reynolds Avatar answered Jan 06 '23 14:01

Vineet Reynolds