Packaging dependent libraries in Jar file

Sometimes developers release Java based applications as distributable Java Archive or JAR files.Most of the time, my applications are JAR files only.The major concern lies with dependent external library files.The final released JAR file look ugly, accompanied by a directory containing external libraries.It will be total mess when user will some how miss one library file.In one go it can be a nightmare for programmer when the user will go insane because of this.
Q. So, what’s the solution ?
Ans. Good news !! There are multiple methods to package dependent libraries into the final JAR file.


Till now I’ve used only one IDE, JBuilder that has inbuilt option to include external libraries into the JAR file.

  • Latest version of JBuilder (2007 onwards)is developed on top of Eclipse and it has option to export dependencies into the distributable JAR file.
  • Earlier version of JBuilder had option through archive builder wizard.
  • There is one simple glitch in this nifty looking option. JBuilder is not free.

Ok..It won’t be out of context to admit this IDE is smouldering hot and I’ve have huge crush on this chick.

  • Hotness apart, NetBeans uses Apache Ant for building project.Here all we need to do is tweak the build.xml file in the NetBeans project to include external libraries.

    Click on Files tab to locate build.xml and open it.
    Append the following Ant build target code above .

    Note: Make sure that you change MyApp to the name of required JAR file.

    Choose Run Target, scroll down to select Other Targets, then choose package-for-store.

  • Here is one article from NetBeans’ wiki about bundling dependencies in one single JAR using OneJAR.

    Article very well explained (rather spoon-feeding redefined) and more useful for those who have multiple projects using same or little varied libraries .

Personally, I don’t use this IDE . But, there is one cute little plugin for Eclipse called FatJar which works like a charm.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *