GenJar : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

GenJar
Introduction Real Life Build Script
Installing GenJar2 Tips
Advantages Advanced GenJar
Disadvantages Recompiling
What Classes Get Included? Links

Introduction

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. GenJar 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 Genjar2 1.4 Last revised/verified: 2010-11-10

 GenJar stopped working properly with the release of Ant 9.0. Genjar1 works for 90% of my apps. For the rest I must revert to jar.exe. I have not yet been able to get GenJar2 working at all. My questions to the author were ignored. I think he has lost interest in the project.

Installing GenJar1

  1. Download Genjar1
  2. Unzip it. I have cleaned up the zip so even WinZip can read it.
  3. Copy genjar.jar and genjar.properties to J:\Program Files (x86)\apache-ant-1.9.0\lib
  4. Use it in place of the jar task in your ant script. See below for an example.

Installing GenJar2

Unless you plan to modify the Genjar source code, you don’t want to do this.

  1. Install Mercurial (e.g. Tortoise HG) so you can access the Google repository.
  2. Clone the server repository (check out the project) on your local hard drive with a Mercurial command: hg clone https://code.google.com/p/genjar2/ E:\genjar2
  3. Read the manual embedded in the repository, now copied to your local hard disk.
  4. rebuild genjar.jar with build.xml.
  5. Copy genjar.jar and genjar.properties to J:\Program Files (x86)\apache-ant-1.9.0\lib. Everything so far you need do only once.
  6. Compose your <genjar XML ANT (A Neat Tool) script and or incorporate it into an ant build.xml in the project directory with the class files where you want the jar built.
  7. CD (Change Directory) to that project directory.
  8. 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. You might have some old *.java or *.class files lying about confusing it. Especially check anything with an old date to make sure it should be included. Ahem. It is considered polite when a program complains about being unable to find something to divulge what it is.

Advantages

Disadvantages

What Classes Get Included?

GenJar scans the classpath looking recursively for classes to include in the jar. These it includes in the jar. Classes in the ext directory, by default, it leaves out of the jar.

You can force it to include certain classes or tell it not to include certain classes because they will be supplied at run time in an auxiliary jar.

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 are no properties to speak of in genjar.properties, just the name of the Java class that extends Task to implement GenJar. 

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

Tips

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. Everything is included, needed or not! 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

Recompiling

You might want to recompile GenJar to fix bugs, to figure out how it works etc. You will have to add the Ant jars to the project. GenJar.jar does not have a main-class in the manifest. Ant learns about the genjar.properties file from the taskdef statement in the ant script. It reads it and discovers the class org.apache.tools.ant.taskdefs.optional.genjar.GenJar which extends the abstract Ant Task class. Ant can dynamically load Genjar with Class.forName.asSubClass.newInstance. Ant can then call GenJar’s methods as needed.


This page is posted
on the web at:

http://mindprod.com/jgloss/genjar.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\genjar.html
logo
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.
Blog
IP:[65.110.21.43]
Your face IP:[54.161.236.229]
You are visitor number