LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   no PATH variable set but still javac working fine in Ubuntu. How ? (https://www.linuxquestions.org/questions/linux-software-2/no-path-variable-set-but-still-javac-working-fine-in-ubuntu-how-813530/)

daudiam 06-11-2010 05:20 AM

no PATH variable set but still javac working fine in Ubuntu. How ?
 
Hi

I thought that setting up the PATH variable was a must if we wanted to use java or javac commands on linux (preferably in the bashrc file), but I am able to use these commands anywhere without setting up the PATH variable.. Similarly, without specifying '.' in the CLASSPATH variable (in fact, not specifying the CLASSPATH variable at all), I am able to access class files in the same directory. How is it possible ?

knudfl 06-11-2010 07:24 AM

One java path has been set up by default.
Usually gcc-java ? Please check with : java -version
( The set up is very simple : 2 links to /usr/bin/ : java + javac.)

Changing the java to e.g. sun-java :
( sun-java6-jdk must be installed.)

sudo update-alternatives --config java
... and choose sun.

CLASSPATH : Today it is "always" /usr/share/java/ , I think.
Is also set to that as default.
..

daudiam 06-13-2010 12:39 AM

Thanks, but does it mean there is another Java installed other than Sun Java 6, which we refer to when we type 'java' and 'javac' because it gets these commands at /usr/bin whereas java as such is installed somewhere else ?

When I type java -version it shows this :

Code:

daud@daud-laptop:~$ java -version
java version "1.6.0_15"
Java(TM) SE Runtime Environment (build 1.6.0_15-b03)
Java HotSpot(TM) Server VM (build 14.1-b02, mixed mode)

Here its showing its using java6

Also, when I type echo $CLASSPATH it shows nothing. Sorry i don't understand that CLASSPATH is the path that's searched in order to find out the class files. When its not set even then its able to find the class files in the present directory (and all books say that '.' must be included in the CLASSPATH for the present directory to be searched)

knudfl 06-13-2010 01:24 AM

Sorry, I was wrong : No default libgcj* gij* in Ubuntu.
( You have an (old) genuine sun java = 1.6.0_15 ).

Still guessing : If you have a particular classpath,
you must point to it, like this example :
'java -classpath ".:./lib/alloy.jar:./lib/gnujaxp.jar:....." <Main>'

Options, please see : java -help
QUOTE : "" -classpath
<class search path of directories and zip/jar files>
A colon ( : ) separated list of directories, JAR archives,
and ZIP archives to search for class files. ""

A "standard" program ( Ubuntu package ) will probably
always use the jar files in /usr/share/java/ .
= The hard coded classpath.
The configuration of $CLASSPATH : Probably inside java itself.
..

daudiam 06-14-2010 12:09 AM

Actually, when I typed ls -l
Code:

/usr/bin/javac
it showed that the javac file here is actually a link to the /etc/alternatives directory's java. In the /etc/alternatives directory I typed
Code:

update-alternatives --list javac
, I got the actual location of the javac. The alternatives system is there to present the user with a single interface for accessing different programs, i.e. he could type javac to invoke the javac of any of Java's versions that are installed.

As for the classpath, the current directory is the default classpath


All times are GMT -5. The time now is 07:56 PM.