Get What You Need From a JAR with Harvester

A few months ago I started to write a small tool called Harvester. It was originally designed to be used in the SwingX project but it actually works with any other project. Harvester is able to find all the dependencies of a class and pack them into a single JAR file. If you need to use a single SwingX component, for instance the JXImagePanel, and you don't want to deal with the full JAR, you can run Harvester against org.jdesktop.swingx.JXImagePanel and get a JAR containing the only things you need to use this component.

Harvester works using an XML configuration file in which you define the components you want to extract from the project. Harvester ships with an example very easy to understand. You'll notice descriptions that are not used by Harvester but meant for tools based on top of Harvester. Anyway, you can hack into harvester-config.xml and run:

java -jar harvester.jar

It should generate your JAR after a few seconds. You can also read the README file to learn more about the command line options. Also know that a meta-component, as defined in the XML file, is just an aggregate of other components defined in the document.

Shortly after releasing this tool on the SwingLabs mailing list, someone mentionned the Ant optional task called classfileset which does exactly the same thing as Harvester. Well Harvester goes just a bit further but there's not much difference. Besides, from what I can read in the documentation, it seems both tools are implemented with the same technique. Nevertheless, Harvester might come in handy when you need to extract one or more classes from a given project once. Just think of the Ant task if you want to apply this to your own project.

Harvester and its sources are available under BSD license. Enjoy!

Comments are closed.