Re: Java command line classpath wildcards

Discussion in 'Java' started by John B. Matthews, Dec 12, 2008.

  1. In article <>,
    Spud <> wrote:

    > After much misery, I discovered the solution to a problem using
    > wildcards in the classpath on the java command line. I post it here just
    > in case someone else has this problem and is lucky enough to type the
    > right words into Google to find it.
    >
    > This does not work:
    >
    > java -cp lib/* MyClass
    >
    > JDK 1.6 supports wildcards on the classpath. If the lib directory
    > contains a bunch of jar files, they won't get picked up correctly with
    > this line. On my system I get this error:
    >
    > "Exception in thread "main" java.lang.NoClassDefFoundError:
    > lib/commons-collections-3/2/jar"
    >
    > (That's one of the jar files in the lib dir).
    >
    > This works:
    >
    > java -cp lib/*; MyClass
    >
    > With the semicolon all is well. That little semicolon cost me half a day
    > of work. Note that the semicolon is used on Windows; it's probably a
    > colon on Unix, but I haven't tried it.


    I'd have expected "java -cp lib/*;. MyClass" as "the -classpath
    command-line option overrides that default, so if you want to include the
    current directory in the search path, you must include "." in the new
    settings."

    <http://java.sun.com/javase/6/docs/technotes/tools/windows/classpath.html>
    <http://java.sun.com/javase/6/docs/technotes/tools/solaris/classpath.html>

    --
    John B. Matthews
    trashgod at gmail dot com
    http://home.roadrunner.com/~jbmatthews/
    John B. Matthews, Dec 12, 2008
    #1
    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,070
  2. Thomas Kellerer
    Replies:
    5
    Views:
    34,570
    Nomak
    Apr 13, 2005
  3. Tom Anderson
    Replies:
    0
    Views:
    1,990
    Tom Anderson
    Dec 13, 2008
  4. Lew
    Replies:
    0
    Views:
    527
  5. Lew
    Replies:
    1
    Views:
    475
Loading...

Share This Page