Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I set CLASSPATH?

Tags:

java

classpath

I did this before:

CLASSPATH=".:/home/phoenies/jdk1.6.0_17/lib/tools.jar:/home/phoenies/jdk1.6.0_17/lib/dt.jar"

But today an article says I should do this:

CLASSPATH=".:/home/phoenies/jdk1.6.0_17/lib"

If I do so, will it search all the jar files in lib? So it's probably a shorter way?

like image 723
phoenies Avatar asked Jan 07 '10 02:01

phoenies


3 Answers

Since you are using JDK6, you can use classpath wildcards: CLASSPATH=".:/home/phoenies/jdk1.6.0_17/lib/*" will match all JARS inside lib/

Check out http://java.sun.com/javase/6/docs/technotes/tools/windows/classpath.html there's a section called "Understanding class path wildcards"

like image 190
Cesar Avatar answered Oct 03 '22 08:10

Cesar


I think having a CLASSPATH environment variable is wrong for all but the easiest of "Hello, World" tutorials.

The right way is to set the CLASSPATH for every project when you compile and run. Every project is likely to be different, so this makes perfect sense.

IDEs ignore CLASSPATH environment settings; so do all Java EE app servers. It's a relic of Java 1.0. I don't have CLASSPATH set on any machine that I work on.

Learn to script it for the command line. Or use Ant. You'll be glad you did.

like image 35
duffymo Avatar answered Oct 03 '22 08:10

duffymo


Yes, it will search all jar files in lib if you do it the second way. It's pretty odd to see class path being set as specifically as in the first one. I suppose on a server where you wanted to be sure what jars were being loaded, that might be one way to restrict them, but you might run into issues with how long it can be if you had several jars.

like image 28
Jim L Avatar answered Oct 03 '22 09:10

Jim L