PDA

View Full Version : Java path


eggsy85
1st October 2004, 07:41 PM
Hi all

Does anyone know how to setup the PATH for Java in Linux?

I have installed JDK1.5.0 to the following dir

/usr/local/JDK1.5.0

And I am looking to have it that when I open the Konsole I can do javac or java etc from anywhere, without having to change directory?

So i can just do javac from anywhere no matter what my current working directory is?

Thanks all

James

ilja
1st October 2004, 07:51 PM
see this : http://www.fedoranews.org/tchung/sunjava/

fjleal
1st October 2004, 11:03 PM
You can also simply add ":/usr/local/jdk1.5.0/bin" to your "PATH" line in ".bash_profile".

raindog
15th October 2004, 01:41 AM
You might also wish to add:
CLASSPATH=/usr/local/jdk1.5.0/lib:.
in your .bash_profile also.

crackers
15th October 2004, 05:20 AM
You might also wish to add...
Do NOT add a CLASSPATH! That went the way of the dodo with Java 1.3 - the JVM will automagically locate the runtime libraries and the "." (dot) is always assumed. This causes more problems than it (supposedly) solves, especially when using IDE's that manage the ClassPath themselves. Plus, this breaks the ability to use "executable" Jars at times...

james_in_denver
15th October 2004, 05:45 AM
But what about "foreign" jars?

still need a CLASSPATH for them.

crackers
15th October 2004, 07:12 AM
Nope - you don't need to set $CLASSPATH to use other jars. There are two other mechanisms that you can use:

1) put the other jars in the .../jre/lib/ext directory (not recommended as this makes those jars available to every JVM run on the system);

2) use the -classpath (for javac) and -cp (for java) command-line options

#2 is quite ideal for use in scripts, since you can then use script variables to build up the ClassPath statically or dynamically.

If you feel that you absolutely need to use an environment $CLASSPATH, the recommended procedure is to do that only "locally" in a terminal process. That way you won't mess up other Java programs and the variable is gone when the terminal environment terminates. To be honest, the only time I use this last method is when I'm using WebLogic command-line utilities for the first couple of times, until I get a handle on what I need to put in a script.

One of the best reasons to not use $CLASSPATH (and option #1) is if you put, say xerces.jar in the $CLASSPATH and then invoke Ant (especially an older version). Which version of Xerces gets used: the one in the antlib or the one on the $CLASSPATH?

Freiberg Photos on Instagram - Znomenka - Kunwi Photos on Instagram