The Class-Path
attribute. This is a standard attribute defined by the JAR file specification. It contains a list of relative URLs for that will be included on the runtime classpath when you run the JAR using java -jar ...
.
This provides a way to add external JARs (and directories) to the runtime classpath. The entries must be relative, and are resolved relative to the directory containing the main JAR. (For security reasons ...)
The Rsrc-class-Path
attribute is non-standard. This is used by Eclipse's "jars-in-jar" launcher. A typical manifest looks like this:
Manifest-Version: 1.0
Rsrc-Main-Class: com.abc.Master
Main-Class: com.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader
Rsrc-Class-Path: ./ lib/xyz.jar
where com.abc.Master
is your apps (real) main class, and lib/xyz.jar
is a relative URL for a JAR file that is nested within this JAR.. You will also see that the JAR contains the ".class" file for JarRsrcLoader
.
This is what happens with you run java -jar this.JAR arg1 arg2
.
- The JVM is created
- The JVM jar loader opens the JAR, reads and parses the MANIFEST.MF above.
- It loads the
JarRsrcLoader
class given by Main-Class
/
- It calls the above classes
main
method, passing it ["arg1", "arg2"]
- The
JarRsrcLoader
examines the manifest, and extracts the Rsrc-Class-Path
and Rsrc-Main-Class
.
- Then
JarRsrcLoader
creates a special classloader that knows how read JARs embedded within the current JAR. The classpath for this classloader is "./" follows by "lib/xyz.jar", where these URLs are resolved within the outer JAR file.
- Then
JarRsrcLoader
loads the class com.abc.Master
using the special class loader.
- Then
JarRsrcLoader
calls the main
method for com.abc.Master
, passing the same string array containing the arguments.
- Finally, the application runs.
In short, Rsrc-Class-Path
is an attribute that the JarRsrcLoader
class understands, and uses to construct the actual application classpath.
In this context, the Class-Path: .
attribute serves no real purpose. Everything needed to run JarRsrcLoader
will be in the JAR.
As a final note, the SpringBoot loading mechanism is similar, but it uses a different non-standard attribute for the application's main class, and puts the application's resources (e.g. JARs) into a particular directory ("/boot-inf") within the main JAR.