Reputation: 1990
I have Ubuntu 10.10 with java already installed. I am able to execute java command from any folder. I supposed that could be because I had java Classpath setted. But neither JAVA_HOME nor CLASSPATH are setted.
If I look at /etc/environment content I can see that PATH is setted to /usr/bin/ (among others). As 'which java
' returns /usr/bin/java, is that the reason why I can execute java from anywhere? If not, why is it?
Upvotes: 0
Views: 401
Reputation: 2878
Yes, if java binary (or a link to it) is on a folder that is listed on the path then you can execute java without specifying the path to it (for example /usr/local/java/latest/bin/java -jar x.jar
)
JAVA_HOME and CLASSPATH have nothing to do with system path.
JAVA_HOME allow other software (or scripts) to know where to look for java installation.
CLASSPATH tells java where to look for classes (.class files resulting of compiling .java files).
Upvotes: 1
Reputation: 70909
You can execute java because the command is on your path.
echo $PATH
will show you which directories are searched, in which order to find a particular program. Since /usr/bin
is on your path, when you type java
it will eventually look at /usr/bin/java
. Note that in many systems this is a symbolic link (a file that points to another file) so /usr/bin/java
often points to /etc/alternatives/java
(which is also a symbolic link that points to the real executable).
Where the environmental variable JAVA_HOME
comes into play is in tools and programs that check for JAVA_HOME
and act on it instead of relying on the path. In most modern Linux systems, the work done by the alternatives subsystem replaces the earlier (more problematic) JAVA_HOME
technique. That said, you might want to set JAVA_HOME
anyway, should you encounter a tool that demands it.
One reason why JAVA_HOME
is not as popular as it could be is that to access JAVA_HOME
you need to run a shell, and not everyone wants to wrap every single Java item in a shell command.
Upvotes: 3