java -jar ignore the classpath command line argument

N

Nomak

Is it normal that when starting a jar, the -classpath command line option is ignored?

$ cat A.java
class A {
public static void main(String[] args) {
System.err.println("java.library.path = " +
System.getProperty("java.library.path"));
System.err.println("java.class.path = " +
System.getProperty("java.class.path"));
}
}


$ cat MANIFEST.MF
Main-Class: A


$ echo $CLASSPATH


$ javac A.java && jar -cmf MANIFEST.MF A.jar A.class && java -classpath 'xerces-2_5_0/xercesImpl.jar' -jar A.jar
java.library.path = /usr/java/j2sdk1.4.2_07/jre/lib/i386/client:/usr/java/j2sdk1.4.2_07/jre/lib/i386:/usr/java/j2sdk1.4.2_07/jre/../lib/i386:/usr/X11R6/lib:/usr/X11R6/lib/modules
java.class.path = A.jar


$ java -version
java version "1.4.2_07"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_07-b05)
Java HotSpot(TM) Client VM (build 1.4.2_07-b05, mixed mode)
 
N

Nomak

Is it normal that when starting a jar, the -classpath command line option is ignored?

Yes. Read the documentation at
http://java.sun.com/j2se/1.4.2/docs/tooldocs/linux/java.html

"When you use this option [-jar], the JAR file is the source of all user
classes, and other user class path settings are ignored."

Thx

but my program must load xerces dynamicaly, how can i do?

(i tried to set the "Class-Path:" header in the manifest, but first it doesn't do anything, and then it would mean that xerces must be at the same location on all the computer where my program must run?!)
 
T

Tor Iver Wilhelmsen

Nomak said:
Is it normal that when starting a jar, the -classpath command line
option is ignored?

Yes, you need to add a

Class-Path: xerces-2_5_0/xercesImpl.jar

line to the manifest file.
 
D

Daniel Dyer

Thx

but my program must load xerces dynamicaly, how can i do?

(i tried to set the "Class-Path:" header in the manifest, but first it
doesn't do anything, and then it would mean that xerces must be at the
same location on all the computer where my program must run?!)

It only has to be in the same relative location, not the same absolute
location. So if you set the classpath in the manifest like this...

Class-Path: xercesImpl.jar

....you would need to deploy xercesImpl.jar in the same directory as your
jar file.

If you use...

Class-Path: lib/xercesImpl.jar

.... then the Xerces jar would have to be in a "lib" directory beneath the
directory where your jar file is.

So it doesn't matter if your app is installed in "C:\Documents and
Settings\username\My Documents\yourapplication" on Windows or
"/home/username/yourapplication" on Linux, or in any other location on any
supported platform. It will work on both so long as the file tree below
"yourapplication" is the same.

Dan.
 
N

Nomak

It only has to be in the same relative location, not the same absolute
location. So if you set the classpath in the manifest like this...

Class-Path: xercesImpl.jar

...you would need to deploy xercesImpl.jar in the same directory as your
jar file.

If you use...

Class-Path: lib/xercesImpl.jar

... then the Xerces jar would have to be in a "lib" directory beneath the
directory where your jar file is.

So it doesn't matter if your app is installed in "C:\Documents and
Settings\username\My Documents\yourapplication" on Windows or
"/home/username/yourapplication" on Linux, or in any other location on any
supported platform. It will work on both so long as the file tree below
"yourapplication" is the same.

Thx a lot, it works
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top