META JAR UTILITIES free! JARS rated top 5%
see other Java utilities at:
Yagga's Java pages!

Three classes with full source code and documentation that allows to extract resources from a file, from inside a JAR file that is currently executing (java -jar foo.jar), from a JAR that is included in the aforementioned executing JAR and to define a classLoader that can work with JARs, even if those JARs are JARred inside the currently executing JAR.

From release 1.7 MetaJarUtilities are being distributed with full source code
under GNU's General Public License. and APACHE License.

[Zip APACHE license ] [Zip GNU license ](133K)
[browse the API's javadoc files]

[an error occurred while processing the directive]
Version 1.5
Version 1.0

1.2, 1.3 and 1.4
date: 16/Aug/2002
Walter Gamba
e-mail ware
inside Yagga framework: YES

If you use it in any of your projects I'd like to hear from you. If the project is commercial, please ask before using the classes.

Everything should be transparent to the user, so if you test the application without compacting it with 'jar', it should work, and it should work even when it will be jarred, or partially jarred etc..

To see a concrete example of how it works, see the MiniInstaller.

The typical layout is:


 +- MyClass
 +- BootstrapJarClassLoader

 +- BUNDLE.jar

 |   +- Test.class

 |   +- ResourceMgr.class

 |   +- DATA/

 |       +- girl.jpg
 +- JARS/
     +- SUB.jar
In this case, when running "java -jar FOO.jar" MyClass, using BoostrapJarClassLoader loads classes from BUNDLE.jar and executes them. Besides classes inside BUNDLE.jar can access files that resides in their JAR (which is JAR-red inside Foo.jar) via ResourceMgr. The trick can go on further on and Test.class can load classes or execute the Jar named SUB.jar!!

What you have in the ZIP

  • in src/ you will find the sources
  • in bin/ the binaries
  • in javadoc/ the JAVADOC of the classes
  • in ./ the files needed for the test
  • in ./readme.txt this tiny manual

test for MetaJarUtilities

simply run maketest.bat (in unix and then copy "supermetatest.jar" in an empty directory and run it.

you can experiment with "metatest.jar" or the various .class file to see how the behaviour is the same (and also the code you have to write) regardless of where

  • the resource are located
  • the class using the resources is located

For the moment being a JAR structured like this works:

 +- SuperMetaJarTest.class (uses BootstrapJarClassLoader.class)
 +- net/
 |   +- yagga/
 |       +- util/
 |           +- BootstrapJarClassLoader.class
 +- metatest.jar (content below)
 |   +- net/
 |   |   +- yagga/
 |   |       +- util/
 |   |           +- Meta Jar Utilities classes here...
 |   +- jars/
 |   |   +- test.jar
 |   +- TestmetaJar.class
 |   +- text.txt 
 +- jars2/
     +- test2.jar

It works because SuperMetaJarTest calls and executes the jar "metatest.jar" via a BoostrapJarClassLoader (a convenience class that encloses all the MetaJarUtilities in one class).

This jar looks for a file named "text.txt" (resides in the same jar, while the jar is executed from inside a jar.

It then executes a parallel jar (a jar on the same level of hyerarchy as metatest.jar) i.e. "jars2/test2.jar". This works even if the test suite is not jarred, or if it is partially jarred (only metatest.jar).

Currently it is not possible (but should be no great pain achieving it) calling "test/test.jar" from inside metatest.jar. (this should be a jar inside a jar inside the executing jar.. quite unlikely).

Yagga's Java pages are copyright(C) 1999
Walter Gamba

Yagga server and PbML are copyright (C) 1999
of Marco Becchio and Walter Gamba