Re: Java classpath question and how to run a program from command line?

Discussion in 'Java' started by Lew, Nov 29, 2011.

  1. Lew

    Lew Guest

    www wrote:
    >> Now, I can make it work:
    >>
    >> java -classpath "/cygdrive/d/project/libs/*;." A.B.C.MainWindow
    >>
    >> by adding the pair of " on the parameter after -classpath AND libs/*,
    >> not libs only. Both corrections are needed to make it work.


    Well, duh.

    Except you forgot to switch to Windows nomenclature ("D:/", not "/cygdrive/d/").

    You need the quotes because bash sees the semicolon as a statement terminator. Remember? You could also have escaped the semicolon with a backslash instead of using quotes.

    You need the asterisk for the reason stated upthread. Did you review the rules for classpath specification as two respondents suggested? It's very basic stuff - the JARs must be called out explicitly, or since recently witha wildcard. You don't pick up JARs just by listing the directory. As stated in the tutorials and documentation. Which you should study.

    > Sorry, I have to correct the command above. I can only make it work by
    > using relative path, not absolute path. In another words, I need to be
    > at /cygdrive/d/project/bin/ first, then use this command:
    >
    > java -classpath "../libs/*;." A.B.C.MainWindow
    >
    > The following command does not work and I don't understand why:
    >
    > java -classpath "/cygdrive/d/project/libs/*;." A.B.C.MainWindow
    >
    > The error message shows that A.B.C.MainWindow was found and loaded,
    > however, those JAR files were not found and loaded. I have added root
    > "/" to the classpath, and the error is the same:
    >
    > java -classpath "/;/cygdrive/d/project/libs/*;." A.B.C.MainWindow


    Well, duh. Did you read the answer upthread for that? Someone already explained this to you. You should read the answers that people here generously provide for free at your request.

    "java" is a Windows program. It does not recognize Cygwin paths. Again wetell you.

    You even got a link upthread for the "java" command and how it takes parameters. You should read the answers that people here generously provide for free at your request. And the Java documentation.

    --
    Lew
    Lew, Nov 29, 2011
    #1
    1. Advertising

  2. Lew

    Lew Guest

    www wrote:
    > After learning that, there is one more correction in .bashrc file:
    > using ":" not ";" to separate the two:
    >
    > export CLASSPATH="/cygdrive/d/project/libs/*:/cygdrive/d/project/bin"


    > Now, no matter which directory I am at, this command will run my
    > program:
    >
    > java -classpath `cygpath -wp $CLASSPATH` A.B.C.MainWindow


    It's usually a bad idea to use CLASSPATH. Java tries to read it by default, so you already made a mistake by applying cygpath after setting the variable instead of before.

    export CLASSPATH=`cygpath -wp "/cygdrive/d/project/libs/*:/cygdrive/d/project/bin"`

    Besides that, using it in conjunction with -cp is silliness. Just use -cp.

    CLASSPATH is usually too global.

    --
    Lew
    Lew, Nov 29, 2011
    #2
    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,049
  2. Thomas Kellerer
    Replies:
    5
    Views:
    34,510
    Nomak
    Apr 13, 2005
  3. John B. Matthews

    Re: Java command line classpath wildcards

    John B. Matthews, Dec 12, 2008, in forum: Java
    Replies:
    0
    Views:
    530
    John B. Matthews
    Dec 12, 2008
  4. Tom Anderson
    Replies:
    0
    Views:
    1,972
    Tom Anderson
    Dec 13, 2008
  5. Lew
    Replies:
    0
    Views:
    514
Loading...

Share This Page