Reputation: 2666
I have an academic question for which I don't find the appropriated documentatino from Sun/Oracle.
I have a set of Jar files and the java vm is started like this:
java -cp one.jar:two.jar:helper.jar my.company.project.Main
As you can see I don't use the -jar option but give a classpath. The helper.jar only has a manifest file defining a Class-Path containing the remaining jar files that are needed.
As I'm not using the -jar command line option I'm wondering if that manifest Class-Path is evaluated and used. (Yes, I know what -jar does, I know what Main-Class is for and I know how to use the Class-Path in conjunction with -jar. I only don't know if it works without using -jar)
Or to clarify my question: does it work reliable and is somewhere documented in an official Sun/Oracle document?
Thank you
Upvotes: 0
Views: 1218
Reputation: 4989
The class-path entry from a JAR file's manifest is always used to extend the classpath when loading classes from that JAR. It does not make a difference if you use the -jar
switch or not.
I was in fact surprised about this behavior, but it is easily reproduced with a simple example using two classes A and B. Let A reference B. Put each class in its own JAR file. Add a manifest to A.jar that includes Class-Path: B.jar
. Then the following command will correctly resolve B: java -cp A.jar A
.
This is also described here How the Java Launcher Finds JAR-class-path Classes section How the Java Launcher Finds JAR-class-path Classes.
Upvotes: 2