![]() |
|
|
|||||||
![]() |
Java - java -jar ignore the classpath command line argument |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
On 13.04.2005 10:47 Nomak wrote: > 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/...inux/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." Thomas Thomas Kellerer |
|
|
|
|
#2 |
|
Posts: n/a
|
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) |
|
|
|
#3 |
|
Posts: n/a
|
On Wed, 13 Apr 2005 10:47:43 +0200
Thomas Kellerer <> wrote: > > > On 13.04.2005 10:47 Nomak wrote: > > > 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/...inux/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?!) |
|
|
|
#4 |
|
Posts: n/a
|
Nomak <> writes:
> 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. |
|
|
|
#5 |
|
Posts: n/a
|
On Wed, 13 Apr 2005 11:09:58 +0100, Nomak <> wrote:
> 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. -- Daniel Dyer http://www.footballpredictions.net |
|
|
|
#6 |
|
Posts: n/a
|
On Wed, 13 Apr 2005 11:59:59 +0100
"Daniel Dyer" <> wrote: > On Wed, 13 Apr 2005 11:09:58 +0100, Nomak <> wrote: > > > 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. > Thx a lot, it works |
|