Which java compiler do u use?

Posted on: January 8, 2008

The other daywhen i  was compiling some code in java,I had a doubt regarding the java packages installed on my ubuntu desktop i have both the Sun java and the GNU libgcj versions installed on my system. The problem here is, how to easily tell which java compiler to use, the sun version or other?On googling ive found the “alternatives system”.I thk itz really a great feature of Debian.

Now let us get into the topic.Check whether which version ur using…

# java -version
java version “1.6.0”
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

Now letus inspect the java binary

# which java
# ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 2007-11-25 16:57 /usr/bin/java -> /etc/alternatives/java
so we can see that java command is being executed from the /usr/bin path,and it links to /etc/alternatives/java,where all the alternatives are configured.


# ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 36 2008-01-08 15:51 /etc/alternatives/java -> /usr/lib/jvm/java-6-sun/jre/bin/java
so we find another link,referring to /usr/lib/jvm/java-6-sun/jre/bin/java and it is linked to real executable.This way the alternatives system works..its very confusing to have all these links pointing to other links and so on.The alternatives system  will link the executable in the default path to the relevant file in /etc/alternatives and this will link to the executable.So it becomes really easy to just update the link in alternatives directory and ink it to the executable we want to use. A nice tool for managing these links is “update-alternatives”.

# /usr/sbin/update-alternatives –display java
java – status is auto.
link currently points to /usr/lib/jvm/java-6-sun/jre/bin/java
/usr/bin/gij-wrapper-4.1 – priority 41
slave java.1.gz: /usr/share/man/man1/gij-wrapper-4.1.1.gz
/usr/lib/jvm/java-6-sun/jre/bin/java – priority 63
slave java.1.gz: /usr/lib/jvm/java-6-sun/jre/man/man1/java.1.gz
Current `best’ version is /usr/lib/jvm/java-6-sun/jre/bin/java.

I think u can understand evrything easily now..acc to the priority the best version is decided,as in this case is Sun java….and as the  java – status is auto..the best version is your default compiler…now if u want to change it to other for any personal reasons

#sudo /usr/sbin/update-alternatives –config java
There are 2 alternatives which provide `java’ Selection    Alternative
1    /usr/bin/gij-wrapper-4.1
*+        2    /usr/lib/jvm/java-6-sun/jre/bin/java
Press enter to keep the default[*], or type selection number:
choose the version u like to use….i choose GNU let us see where the link points to:

# /usr/sbin/update-alternatives –display java
java – status is manual.
link now points to /usr/bin/gij-wrapper-4.1

So uve Sucessfully changed it to GNU version as in my case.Verify it by java -version

PS 1:plz note that there are two hyphens b4 config and display


1 Response to "Which java compiler do u use?"

kranny i am getting an error saying
update-alternatives: unknown argument `–display’

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog Stats

  • 17,004 hits
%d bloggers like this: