A coworker recently asked me how to create one jar file containing a java application and all required libraries. He tought this would make delivering hist application a lot easier. You would just need to start the application using java -jar …. No wories about setting the right classpath or having the right jars.

Although it may sound like an easy way to install an application, just put everything into one big jar file, it also sounds like a waste. Do you really want every application that you install to include all the same libraries? Imagine the lost disk-space if every application installed it’s own log4j, or it’s own jdbc library.

Actually, that’s already happening today. Most application i install have their own lib directory often containing jars already installed elsewere on my system. This is the case with web applications, desktop application, and java webstart applications. Shared libraries are a nice concept but often a source for frustration. Unless ofcourse, you have a tool like apt to manage the installation and all the different versions and dependencies.

Felipe Gaucho recently blogged about a tool which allows you to deliver your application as one jar: Deliver Your Java Application in One-JAR!. This tool, One-JAR enables you to load jar files inside your application jar file through a modified classloader. Which means that you don’t have to unjar and rejar all required libraries. You just put all required jar files inside your main jar file. And if you’re using Eclipse, the Fat Jar Eclipse plugin will do the hard work of create the application jar for you. More info: Simplify Your Application Delivery with One-JAR.