Saturday, May 5, 2012

Making Oracle JAVA work on Ubuntu 12.04

With the suspension of support for more Ubuntu friendly format from Oracle we sometime face issues with installing Oracle Jdk 7 on ubuntu.
I have a 64 bit oracle JDK installed on my system from the following PPA
PPA: http://ppa.launchpad.net/webupd8team/java/ubuntu
you need to perform the following steps for installing the oracle JDK7 on your ubuntu 12.04 64 bit system
1. $> sudo add-apt-repository ppa:webupd8team/java
2. $> sudo apt-get update
3. $> sudo apt-get install oracle-java7-installer
After this you can check and select which java version you would like to use on the system
$>sudo update-alternatives --config java
Once this is done you probably would like to ensure that browser is using this java plugin, for that you need to carry out these options
create a "plugins" directory in the "~/.mozilla" path
$> mkdir ~/.mozilla/plugins 
Now you need to have a soft link to the actual file, which will be responsible for running the java on your browser(mozilla/chrome/chromium all use this plugins directory)   
$>ln -s /usr/lib/jvm/java-7-oracle/jre/lib/amd64/libnpjp2.so ~/.mozilla/plugins
Once this is done you check the oracle link Test Page to see if the java is running fine on your system  
Now you would probably like to run eclipse on your system, for that these is a catch. I was facing issues when i was trying to open eclipse form my system and was getting this error
java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons: 
no swt-gtk-3740 in java.library.path
no swt-gtk in java.library.path
What this means is that the .swt folder at your home directory is missing few files which you need to manually copy. First you need to have following packages installed(generally they are installed if you have Gnome 3) 
$> sudo apt-get install libswt-gtk-3-jni libswt-gtk-3-java
Once you have installed these packages you can proceed to copy files which are needed
$> sudo cp /usr/lib/jni/libswt-*3740.so ~/.swt/lib/linux/x86_64
In case its a i386 install then the command will be 
$> sudo cp /usr/lib/jni/libswt-*3740.so ~/.swt/lib/linux/x86
You could also create the soft link to required files 
libswt-atk-gtk-3740.so -> /usr/lib/jni/libswt-atk-gtk-3740.so
libswt-cairo-gtk-3740.so -> /usr/lib/jni/libswt-cairo-gtk-3740.so
libswt-awt-gtk-3740.so -> /usr/lib/jni/libswt-awt-gtk-3740.so
libswt-gnome-gtk-3740.so -> /usr/lib/jni/libswt-gnome-gtk-3740.so
libswt-glx-gtk-3740.so -> /usr/lib/jni/libswt-glx-gtk-3740.so
libswt-gtk-3740.so -> /usr/lib/jni/libswt-gtk-3740.so
libswt-webkit-gtk-3740.so -> /usr/lib/jni/libswt-webkit-gtk-3740.so
libswt-pi-gtk-3740.so -> /usr/lib/jni/libswt-pi-gtk-3740.so
Once this is done you need to edit the eclipse.ini file to explicitly tell eclipse which VM to use. If you have installed eclipse using the Ubuntu Software Center you need to go to the following path to edit the file
$> sudo gedit /usr/lib/eclipse/eclipse.ini
You can specify the VM by adding these lines in the file
-vm
/usr/lib/jvm/java-7-oracle/bin

Once all these steps are done you should be ready with starting your development in Java on Ubuntu  12.04 64bit.

Enjoy !

References :

askubuntu.com   : http://askubuntu.com/questions/125150/unsatisfied-link-error-and-missing-so-files-when-starting-eclipse
technonstop.com    : http://technonstop.com/install-java-plugin-ubuntu-linux 
Stackoverflow.com    : http://stackoverflow.com/questions/10165693/ubuntu-eclipse-cannot-load-swt-libraries-not-opening

No comments: