简体   繁体   中英

Difference between Rsrc-Class-Path and Class-Path

can someone tell me please what are the difference between Rsrc-class-Path and Class-Path sections of a runnable-jar's mannifest file?

Now I take them as granted as generated by Eclipse, but I'd like to understand how it works.

What I think based on how Eclipse generates code seems that the first is about jars my app needs, the second is always . . But I have no clues what folder . refers to.

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 .

  1. The JVM is created
  2. The JVM jar loader opens the JAR, reads and parses the MANIFEST.MF above.
  3. It loads the JarRsrcLoader class given by Main-Class /
  4. It calls the above classes main method, passing it ["arg1", "arg2"]
  5. The JarRsrcLoader examines the manifest, and extracts the Rsrc-Class-Path and Rsrc-Main-Class .
  6. 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.
  7. Then JarRsrcLoader loads the class com.abc.Master using the special class loader.
  8. Then JarRsrcLoader calls the main method for com.abc.Master , passing the same string array containing the arguments.
  9. 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 (eg JARs) into a particular directory ("/boot-inf") within the main JAR.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM