R71
R71

Reputation: 4523

java classpath in unix

I can run java in cygwin+windows using the following settings (the sw/jar directory has several jar files, and I pick the relevant one from the java command line):

CLASSPATH=.;C:\sw\java_6u35\lib\\*;C:\sw\jar\\*
java org.antlr.Tool Calc.g

But I am having the following problems when running in linux:

(1) I can't set a directory name in a classpath, the following line reports an error:

setenv CLASSPATH .:/sw/jdk1.6.0_35/lib/\*:/sw/jar/*

(2) when I run explictly with -jar option, I still get an error:

java -jar /sw/jar/antlr-3.4.jar org.antlr.Tool Calc.g
error(7):  cannot find or open file: org.antlr.Tool

However, the class does exist. When I do jar tf /sw/jar/antlr-3.4.jar, I get:

...
org/antlr/Tool.class

So my question is: (a) how do I specify in unix that my jar-directory is xxx that contains several jar files, and (2) how do I pick the relevant jar from this dir at runtime?

Upvotes: 1

Views: 32926

Answers (2)

morgano
morgano

Reputation: 17422

in unix use this to set the classpath:

export CLASSPATH=myClassPath

about not finding your jar, you're using a leading slash (/), that means that you path is absolute (not relative to your home folder) is this what you want?

if you want the path to be relative to your folder try:

java -jar ~/mypathToMyJar

Upvotes: 0

user10996
user10996

Reputation:

To specify multiple jars in a directory, directly in the java command, use this

java -cp "/sw/jar/*" org.antlr.Tool Calc.g

This will include all the jars

If you want to set the classpath in Unix/Linux systems, use this

export CLASSPATH=/sw/jar/a.jar:/sw/jar/b.jar

Upvotes: 4

Related Questions