Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > java -jar ignore the classpath command line argument

Reply
Thread Tools

java -jar ignore the classpath command line argument

 
 
Thomas Kellerer
Guest
Posts: n/a
 
      04-13-2005


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
 
Reply With Quote
 
 
 
 
Nomak
Guest
Posts: n/a
 
      04-13-2005
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)

 
Reply With Quote
 
 
 
 
Nomak
Guest
Posts: n/a
 
      04-13-2005
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?!)


 
Reply With Quote
 
Tor Iver Wilhelmsen
Guest
Posts: n/a
 
      04-13-2005
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.
 
Reply With Quote
 
Daniel Dyer
Guest
Posts: n/a
 
      04-13-2005
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
 
Reply With Quote
 
Nomak
Guest
Posts: n/a
 
      04-13-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Java classpath question and how to run a program from command line? Lew Java 1 11-29-2011 08:08 PM
Re: Java classpath question and how to run a program from command line? Lew Java 0 11-28-2011 11:58 PM
Re: Java command line classpath wildcards Tom Anderson Java 0 12-13-2008 11:42 AM
Re: Java command line classpath wildcards John B. Matthews Java 0 12-12-2008 09:50 PM
while using javac -classpath some.jar some.java (Where does classpath get stored?) Gabe Java 3 08-27-2004 07:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57