1

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?

1
  • Which shell are you using on Linux? If setenv is giving an error, it's likely that you're not using csh. Commented Jul 9, 2013 at 13:18

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

Yes I want an absolute path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.