java -jar ignore the classpath command line argument

Discussion in 'Java' started by Thomas Kellerer, Apr 13, 2005.

  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/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."

    Thomas
     
    Thomas Kellerer, Apr 13, 2005
    #1
    1. Advertising

  2. Thomas Kellerer

    Nomak Guest

    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)
     
    Nomak, Apr 13, 2005
    #2
    1. Advertising

  3. Thomas Kellerer

    Nomak Guest

    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/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?!)
     
    Nomak, Apr 13, 2005
    #3
  4. 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.
     
    Tor Iver Wilhelmsen, Apr 13, 2005
    #4
  5. Thomas Kellerer

    Daniel Dyer Guest

    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
     
    Daniel Dyer, Apr 13, 2005
    #5
  6. Thomas Kellerer

    Nomak Guest

    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
     
    Nomak, Apr 13, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gabe
    Replies:
    3
    Views:
    1,093
  2. cyberco
    Replies:
    4
    Views:
    3,811
    Roedy Green
    Feb 14, 2006
  3. John B. Matthews

    Re: Java command line classpath wildcards

    John B. Matthews, Dec 12, 2008, in forum: Java
    Replies:
    0
    Views:
    550
    John B. Matthews
    Dec 12, 2008
  4. Tom Anderson
    Replies:
    0
    Views:
    2,008
    Tom Anderson
    Dec 13, 2008
  5. Lew
    Replies:
    0
    Views:
    542
Loading...

Share This Page