Occasionally there is need to switch between JDK's. For example DrJava works nicely only with JDK downloaded from the Sun website. Also Eclipse and NetBeans may show some funny behaviours if they are using JDK from Ubuntu repositories. But before I go about creating config files and setting up this or that JDK to be default, let me explain how to install any JDK on Ubuntu.
Vanilla Ubuntu JDK
There are two main methods which can be used to install Java Development Kit on Ubuntu. The first one is you use Ubuntu repositories. GUI way is go to System -> Administration -> Synaptic Package Manager. It will ask you for a password. When it is up type in Java into Quick search box. Further, locate the JDK that you want, tick check box next to it (from context menu select Mark for installation) and hit Apply button. Under the bonnet packages will be downloaded, unpacked, installed and symbolic links created. If you want you can use command line and apt-get instead. Go to Applications -> Acessories -> Terminal, when terminal shows up type in:
apt-cache search java | more
That does search for packages which are somehow related to Java. Part of the command '| more' prints single screen at the time; to see the next batch of results hit the space bar. When you locate what you need then you install it:
sudo apt-get install openjdk-6-jdk
sudo gives you temporary root authority and will ask you for password. You may want to install sun-java6-jdk instead, or maybe both of them.
If you decided to install more than one JDK then you may wish to alternate between them from time to time. To achieve that run:
update-java-alternatives -l
That should produce a list of JDK's. What is it and what does it actually do? It is bash script located in /usr/sbin/ and it is part of java-common. To see what else is in java-common use:
dpkg -L java-common
It goes to /usr/lib/jvm/ and looks for *.jinfo files. Those files are hidden files, their name starts with dot, for example .java-6-sun.jinfo. In order to see hidden files in Nautilus press Ctl+H. Their content looks something like this:
name=java-6-openjdk
alias=java-6-openjdk
priority=1061
section=main
hl java /usr/lib/jvm/java-6-openjdk/jre/bin/java
hl keytool /usr/lib/jvm/java-6-openjdk/jre/bin/keytool
...
hl jexec /usr/lib/jvm/java-6-openjdk/jre/lib/jexec
jre javaws /usr/lib/jvm/java-6-openjdk/jre/bin/javaws
jre pluginappletviewer /usr/lib/jvm/java-6-openjdk/jre/bin/pluginappletviewer
jre policytool /usr/lib/jvm/java-6-openjdk/jre/bin/policytool
jdk appletviewer /usr/lib/jvm/java-6-openjdk/bin/appletviewer
...
jdk jar /usr/lib/jvm/java-6-openjdk/bin/jar
jdk jarsigner /usr/lib/jvm/java-6-openjdk/bin/jarsigner
jdk javac /usr/lib/jvm/java-6-openjdk/bin/javac
...
jdk wsgen /usr/lib/jvm/java-6-openjdk/bin/wsgen
jdk wsimport /usr/lib/jvm/java-6-openjdk/bin/wsimport
jdk xjc /usr/lib/jvm/java-6-openjdk/bin/xjc
plugin xulrunner-1.9-javaplugin.so /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/gcjwebplugin.so
If your Firefox or Chrome gives you hard time with Java applets, you know where to look.
Back to list of available JDK's, pick one and set it as default:
sudo update-java-alternatives -s java-6-sun
Now when you try java -version it should print out your current JDK version.
Using JDK which is not from Ubuntu Repository
Usually that is JDK downloaded directly from Sun website. It usually comes as shell script and it is named jdk-6u13-linux-i586.bin; update version may be different. When you run it (double click and select Run from dialogue) it will show EULA and extract JDK right there where you downloaded it. If you expected that it will be installed and become the main supplier of Java Virtual Machine - sorry that is not the case. There are two options, the first one is quick and dirty. In order to make your ~/install/jdk1.6.0_13/bin/java main supplier of Java do the following:
sudo update-alternatives --install /usr/bin/java java /home/JDKPATH/install/jdk1.6.0_13/bin/java 300
sudo update-alternatives --auto java
sudo update-alternatives --install /usr/bin/javac javac /home/JDKPATH/jdk1.6.0_13/bin/javac 300
sudo update-alternatives --auto javac
That should be enough to get you going. If the need arises, you may wish to append more of those symbolic links to the collection.
The more appropriate solution would be how Debian developers are doing it, cd to where JDK is and execute the following:
sudo apt-get install fakeroot java-package
fakeroot make-jpkg jdk-6u13-linux-i586.bin
After the process of packaging JDK is over there should be sun-j2sdk1.6_1.6.0+update13_i386.deb which you can double click to start GDebi and install it. Finally execute:
sudo update-alternatives --config java
It will list what is available on your box and you type in number for /usr/lib/j2sdk1.6-sun/bin/java to set it as default.
No comments:
Post a Comment