简体   繁体   中英

Unused MANIFEST.MF Class-Path

What happens, if there is a manifest Class-Path entry for a jar which doesn't exists at the location, but is available by another means (in the lib-folder of application server for example)

Will the unresolved Class-Path entry cause any errors?

JVM loads & searches classes in following order:

  1. Bootstrap classes - Classes that comprise the Java platform, including the classes in rt.jar and several other important jar files.
  2. Extension classes - Classes that use the Java Extension mechanism. These are bundled as .jar files located in the extensions directory.usually $JAVA_HOME/lib/ext directory.
  3. User classes - Classes defined by developers. Location of these classes using the -classpath option on the command line or by using the CLASSPATH environment variable.

If the JAR-class-path points to a JAR file that was already included (for example, an extension, or a JAR file that was listed earlier in the class path) then that JAR file will not be searched again. (This optimization improves efficiency and prevents circular searches.) Such a JAR file is searched at the point that it appears, earlier in the class path.

To verify this, I also did following test 1. Created lib(jar) "classpath-test" containing a Util class. 2. Created another lib(jar) ie wrapper-lib which uses classpath-test's Util class. 3. In wrapper-lib's MANIFEST.MF, added below entry.

Class-Path: lib/classpath-test.jar
  1. Copied classpath-test.jar under lib dir and ran below command

    java -jar wrapper-lib.jar

Above command Ran fine. Ran same command after deleting lib/classpath-test.jar, and it failed.

  1. Another test, deleted classpath-test.jar from lib & copied in JAVA_HOME/lib/ext and ran

    java -jar wrapper-lib.jar

It worked.

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