3

I've been programming Java on windows for ages and just moved to the Mac.

I'm running the following command which works on the PC but doesn't on a Mac what am I doing wrong.

java -classpath ./lib.patches/*:./lib.core/*:./lib.custom/* test.Test

This gives me a ClassNotFound but test.Test is in a one of the jars in the path.

Thanks for all help.

OK I've debugged further and when I run this command

java -cp . test.Test

I've worked it out!!

The script was copied from a PC and had the wrong returns to end the lines.

This had the bizarre outcome of creating a ClassNotFound.

from the command line it works but from a script it throws ClassNotFound - must be a Mac issue ...

Dan
  • 9,681
  • 14
  • 55
  • 70

3 Answers3

3

Works fine for me. (Escaping to show it's not related to shell globbing, but it works either way.)

With lucene-core in directory 1 and lucene demo in directory 2, or both in a single directory:

...lucene/lucene-3.4.0/tmp $ echo $CLASSPATH

...lucene/lucene-3.4.0/tmp $ java -cp ./1/\*:./2/\* org.apache.lucene.demo.IndexFiles -docs .
Indexing to directory 'index'...
adding ./1/lucene-core-3.4.0.jar
adding ./2/lucene-demo-3.4.0.jar
adding ./index/_0.fdt
adding ./index/_0.fdx
adding ./index/write.lock
1605 total milliseconds

If you also need class files based off the current directory, you should explicitly add the . path to the classpath.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • +1 I get a similar [result](http://stackoverflow.com/questions/7907814/java-on-the-mac/7908432#7908432). – trashgod Oct 26 '11 at 20:23
1

Verifying @Dave Newton's result, using

$ java -version
java version "1.6.0_26"

with ThermometerDemo, this command works:

$ java -cp /opt/jfreechart/*:build/classes chart.ThermometerDemo
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • The [wildcard](http://download.oracle.com/javase/6/docs/technotes/tools/solaris/classpath.html) is new in J2SE 6; cf [this](http://download.oracle.com/javase/1.5.0/docs/tooldocs/solaris/classpath.html). – trashgod Oct 29 '11 at 19:44
0

try

java -cp './lib.patches/*:./lib.core/*:./lib.custom/*' test.Test

instead

A Question Asker
  • 3,339
  • 7
  • 31
  • 39