If you have a relative path in the java class path, does this just search the current working directory. Does the same hold for class paths declared in a manifest file. In a manifest file is it relative to the dir the jar is in?
Ex. Cmdline
java -cp somejar.jar
Or
Manifest
Class-Path: somejar.jar
If you say
-cp somejar.jar
you are addingsomejar.jar
to the classpath. It will only try to find thesomejar.jar
from the directory you are currently in when you typed the command.If you say in the Manifest
you are saying add the jar,
somejar.jar
into the classpath from the directory where the manifest is located(aka inside the jar).As a side note, when you specify the classpath by using -jar, -cp, or -classpath, you override the system variable CLASSPATH.
More details can be found here, http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
You've actually mentioned two different cases:
Case #1
In this case the relative path to the JAR (or whatever) is resolved relative to the current directory.
Case #2
where somejar.jar contains
In this case "foo/bar/somejar.jar" is resolved relative to the current directory (as above), but "anotherjar.jar" is resolved relative to the directory containing "somejar.jar".
(Aside: my understanding is that a Manifest Class-Path: attribute is respected when a JAR file is included via
-cp
or$CLASSPATH
, but it only affects the dependencies of classes loaded from that JAR ... see the "findingclasses" link below.)References: