Monday, August 24, 2009

How-to: Package single jar with netbeans

For desktop application it's quite usefull to package it as single jar and launch as java -jar ...
or wrap it with launch4j and make executable file for you platform(for windows now but also will try for OS X).
The story is short actually - Just add following section into your build.xml file.
<target name="-post-jar">
<jar update="true" destfile="${dist.jar}">
<zipfileset src="${dist.dir}/lib/lib1.jar"/>
<zipfileset src="${dist.dir}/lib/lib2.jar"/>
<zipfileset src="${dist.dir}/lib/lib3.jar"/>
</jar>
</target>

Also some libraries rely on content of MANIFEST.MF file, so actually you need to merge file with same names from all jar in META-INF folder. Will update on solution to this =)

UPD: Article on this topic was published on java.sun.com: http://java.sun.com/developer/technicalArticles/java_warehouse/single_jar/ . No solution for merging MANIFEST.MF files proposed =(

UPD2: You can use exclude tag inside zipfileset to exclude manifest update: META-INF/MANIFEST.MF