<<Build Tools | Home Print Layout | Ant Example>> |
jar
command is
all that is necessary. However, the hierarchical nature of One-JAR files can prove complex to
construct, even when automated within an Ant script.
There is a simple way: an Ant task called <one-jar>
has been created.
This task extends the Ant <jar>
task, so it should be immediately familiar
and usable to those experienced with Ant. To construct a One-JAR file using this task,
simply include the XML fragment that defines the taskdef, and invoke the target.
An outline of the <one-jar>
task is shown below:
<one-jar destfile=... manifest=...> <manifest> Attributes for the manifest of the One-JAR. Use this instead of specifying a "manifest" attribute above <attribute name="attr" value="value"> ... etc. </manifest> <main [jar="main.jar"]> <filesets> which comprise the class-files of the main application. Do not put JAR files in here; rather use the "jar" attribute if you already have a pre-canned main program. </main> <lib> <filesets> containing Jar-files which support the main application. </lib> <binlib> <filesets> containing native libraries. Native libraries are expanded into a temporary directory at runtime: these files are deleted on exit. </binlib> <wrap> <filesets> containing class-loader wrappers. These check classloaders that are loaded from the supporting Jar files to make sure they are compatible with the One-JAR classloader. This is a complex subject, contact one-jar-support for more information and consulting services if you need to wrap a classloader. You will know you need this if your application does not load classes when you expect it should, from JAR files inside the <lib> directory. </wrap> <fileset> Any other stuff you want in the top-level One-JAR file. Remember though, any .class files you put in here will not be able to "see into" JAR files loaded from /main and /lib because their classloader will be the top-level Java Application Loader, which does not understand One-JAR files (this is how One-JAR came about in the first place). Contact one-jar support if you find yourself having problems with this kind of issue. </fileset> </one-jar>