Classpath including JAR within a JAR

Paul Reiners picture Paul Reiners · Oct 8, 2008 · Viewed 148.7k times · Source

Is it possible to specify a Java classpath that includes a JAR file contained within another JAR file?

Answer

Steve Moyer picture Steve Moyer · Oct 8, 2008

If you're trying to create a single jar that contains your application and its required libraries, there are two ways (that I know of) to do that. The first is One-Jar, which uses a special classloader to allow the nesting of jars. The second is UberJar, (or Shade), which explodes the included libraries and puts all the classes in the top-level jar.

I should also mention that UberJar and Shade are plugins for Maven1 and Maven2 respectively. As mentioned below, you can also use the assembly plugin (which in reality is much more powerful, but much harder to properly configure).