GenJar : Java Glossary

GenJar
An open source tool for tracking java dependencies. It builds jar files that automatically contain all the classes used directly or indirectly by the classes you explicitly include. You need this because jar.exe is not clever enough to do this on its own. It runs only as an ant task. It is a complex tool controlled with an XML (extensible Markup Language) script. It will also build an extended manifest describing all the elements. Of course it has no way of knowing about dynamically loaded classes or resources. The latest version is 1.0.2. Last revised: 2003-03-06 Verified: 2010-02-10 to fix exception message regression

To use genjar:

  1. Extract the jar from the archive using WinZip.
  2. Copy genjar.jar and genjar.properties to J:\Program Files (x86)\apache-ant-1.8.2\lib. This is a one-time step. If genjar.jar is not included in your distributable, you will have to build it from source.
  3. Compose your <genjar XML script and or incorporate it into an ant build.xml in the project directory with the class files where you want the jar built.
  4. CD (Change Directory) to that project directory.
  5. Then run your script with:
    ant jar
Don’t use the genjar destdir option. It does not produce a simple list of dependencies to feed to jar.exe but rather a copy of the entire directory tree of classes that would go inside the jar.
Genjar error messages are misleading. It will complain about the main class when the real problem is some totally different class.
When genjar says Unable to resolve: null, it means it could not find some class file it needs to include in the jar, or a file it wanted was in use by another program. Try a reboot. Ahem. It is considered polite when a program complains about being unable to find something to divulge what it is.

Advantages

Disadvantages

Real Life Build Script

This build script builds Biorhythms, a signed Applet. You make genjar known to the script with: <taskdef resource="genjar.properties" /> Oddly there is no genjar.properties file anywhere. This is sufficient to look in GenJar.jar for

Here is how you would include a whole directory full of *.png resource images in your jar:

Advanced GenJar

You can use the <library command to unpack and include some other library jar inside your jar. Unfortunately, the <classfilter command has no effect on just what is included with the <library command. You have to set up the jar to be included on the classpath, then use the <classfilter. You can use the <class command to include just the stuff from a library needed to support a given class. You can use the <classpath command if GenJar seems to be having trouble finding some auxiliary library.

In this example we persuade GenJar to include just the classes used by the TrueZip library jar and bundle them in

ant
Cramfull: ensure all resources included in jar
dependencies
GenJar documentation
jar.exe
xml

CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/genjar.html J:\mindprod\jgloss\genjar.html
logofeedback Please email your feedback for publication, letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email If you want your message kept confidential, not considered for posting, please explicitly specify that.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.214]
You are visitor number 16,229.