2

I'm having some problems specifying multiple.jar files when i compile my project. I'm almost certain that:

sudo javac -classpath .:../lib/*.jar server/*.java models/*.java authentication/*.java database/*.java

would work. Just as with the .java files. But it doesn't.

I just now realised that i have to specify each .jar as following:

sudo javac -classpath .:../lib/gson-2.2.4.jar:../lib/mysql-connector-java-5.1.26-bin.jar server/*.java models/*.java authentication/*.java database/*.java

So, do I really have to add a new .jar to my run.sh shell code each time i need a new .jar?

To sum the question:

-classpath .:../lib/gson-2.2.4.jar:../lib/mysql-connector-java-5.1.26-bin.jar

works.

-classpath .:../lib/*.jar

Does not, why?

0

2 Answers 2

4

You don need to specify *jar you only need to something like this:

-classpath .:../lib/*  

To add all jars. (WIthout .jar suffix) Please read

http://docs.oracle.com/javase/6/docs/technotes/tools/solaris/classpath.html

"Understanding class path wildcards"

For example, the class path entry foo/* specifies all JAR files in the directory named foo. A classpath entry consisting simply of * expands to a list of all the jar files in the current directory. Files will be considered regardless of whether or not they are hidden (that is, have names beginning with '.').

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

Comments

3

You need to quote *, so that the shell does not expand it.

#this doesn't work:
javac -classpath .:../lib/*.jar ...

#the above expands to (notice the space between the jar files):
javac -classpath .:../lib/jar1.jar ../lib/jar2.jar ...

#this should work:
javac -classpath '.:../lib/*' ...

You want javac to interpret the '*', not the shell.

1 Comment

I have a command java -classpath /jars/*:/anotherJarsDir/* com.test.MyClass without any quotes and it works fine. I'm wondering why shell isn't expanding it and erroring out?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.