domingo, 17 de marzo de 2013

Make a single .jar from many

What if  some project require several Java .jar files and for some reason you want to work with a single .jar with all of them inside? Or what if want to distribute your library, that requires several .jar to work, in a single .jar so it is less painful to new users? If you have permission on the other jars this is not a problem at all. The following is a sh script that uses the unzip tool:


rm -rf jartmp
mkdir jartmp
cd jartmp
unzip -u ../path/to/someJarA.jar
unzip -u ../path/toother.jar
unzip -u ../ahother/one.jar
zip -r myLibrary-alldeps.jar *
cd ..
rm -rf jartmp

The previous script will generate a myLibrary-alldeps.jar that contains the three previousgiven .jars files, all inside. This way the user of your library do not have to download your library's dependencies. Hope this serves somebody.