I have added some external libraries to my java project (in netbeans).
Is it possible to put the external jar library to the java archive (and not to put them into a separate (for example) "lib" directory)?
views:
273answers:
6You can recombine a set of JARs into a single JAR assuming the licenses of the third-party JARs permit this kind of redistribution. This is covered in:
The JarJar project allows you to package depend jars into a single jar file for distribution.
The project provides an ant task to do the packaging and as netbeans projects use Ant for their build process, you should be able to integrate it into your build fairly easily.
If it is about packing jars into jars this is always done for web apps in war or ear files. If your app is standalone you can unzip the jars and pack them alltogether in one resulting jar using ants jar and unjar http://ant.apache.org/manual/CoreTasks/unzip.html But I would not recommend to do this.
Yes, this is possible and the resulting jar is actually called an "uberjar" or "megajar". Basically, to create an "uberjar", you'll need to extract the content of the external library (using jar -x
) and to repack it in your own jar (with jar -c
). This can be achieved by hand, or with a build tool like Ant (and the optional support of a project like One-JAR) or Maven which has built-in support for this through the maven-assembly-plugin (or the maven-shade-plugin)
If you are using Maven, you can consider the Maven shade plugin, or the assembly plugin.