|<<Introduction||Home Print Layout||Quick Start>>|
java -jar jarname.jarThe only requirement of the jarname.jar file is that it contains a manifest attribute with the key
Main-Classa main class to run, for instance in the
Main-Class: com.mydomain.mypackage.MainAny non-trivial Java application is going to rely on any number of supporting Jar files. For example, using the Apache Commons Logging capabilty to do logging an application will need to have the
commons-logging.jarfile on its classpath. Most developers reasonably assume that putting a dependency Jar file into their own Jar file, and adding a
Class-Pathattribute to the
META-INF/MANIFESTwill do the trick:
jarname.jar | /META-INF | | MANIFEST.MF | | Main-Class: com.mydomain.mypackage.Main | | Class-Path: commons-logging.jar | /com/mydomain/mypackage | | Main.class | commons-logging.jarUnfortunately this is does not work. The Java
Launcher$AppClassLoaderdoes not know how to load classes from a Jar inside a Jar with this kind of
Class-Path. Trying to use
jar:file:jarname.jar!/commons-logging.jaralso leads down a dead-end. This approach will only work if you install (i.e. scatter) the supporting Jar files into the directory where the
jarname.jarfile is installed.
approach is to unpack all dependent Jar files and repack them inside the
This approach tends to be fragile and slow, and can suffer from duplicate resource issues.