Monday, February 12, 2007

Fedora Eclipse 3.2.0 and jdk-1_5_0

I am leraning Java (trying to at least) and during the installation I was very pleased to see the Eclipse package under the options but the version installed uses jre-1.4.2-gcj. That is the java runtime engine from the gnu project. It is a great effort but to someone who is reading books about java and the Sun version you get to cases where particular clases/packages (I still don't get hold of the names) are not available. Therefore I installed the Sun JDK.

As always after googling a little I found a great how-to and here are my notes. The link to the original post is at the botton of this post.

First download a jdk/jre from Sun. At the moment of writing this version 6 was available. At work I using a tool to create vxml code with eclipse that recommends 1.4.2 so I choose 1.5 (just in the middle).

I downloaded jdk-1_5_0_11-linux-i586.bin. There is a rpm but every site I checked recommends not getting closed to the sun rpm and all prefers to just run the binary.

Once downloaed copy it to /opt directory and give it rights to be executed. The easiest way is chmod +x filename.

Next cd to /opt and just run the binnary.

./jdk-1_5_0_11-linux-i586.bin


This will install everything under the current directory. In my case I ended with /opt/jdk1.5.0_11

Note that the JDK installed Sun JRE so you might want to use this jre instead that the gnu one when browsing the web. So to do this you just create a link on the mozilla

ln -s /opt/jdk1.5.0_11/jre/plugin/i386/ns7/libjavaplugin_oji.so /usr/lib/mozilla/plugins/libjavaplugin_oji.so

If you use firefox don't worry as firefox checks the mozilla plugins.

Now we start with the tricky part. You need to create a file java.sh to include the new paths, in my case I created the following:

[ricardo@mybox]$ more /etc/profile.d/java.sh
export J2RE_HOME=/opt/jdk1.5.0_11/jre
export PATH=$J2RE_HOME/bin:$PATH
[ricardo@mybox]

Once you have this file execute it by typing:

source /etc/profile.d/java.sh

This wll set your new java paths. To check it run the command below:

[ricardo@mybox]$ which java
/opt/jdk1.5.0_11/jre/bin/java
[ricardo@mybox]$


Next step is to run the following command to be able to later change the from gnu java to sun java.

/usr/sbin/alternatives --install /usr/bin/java java /opt/jdk1.5.0_11/jre/bin/java 2

Then type

/usr/sbin/alternatives --config java

This will show you something like this:

[ricardo@mybox]$ /usr/sbin/alternatives --config java

There are 2 programs which provide 'java'.

Selection Command
-----------------------------------------------
* 1 /usr/lib/jvm/jre-1.4.2-gcj/bin/java
+ 2 /opt/jdk1.5.0_11/jre/bin/java

Enter to keep the current selection[+], or type selection number:


In the case above the + sign was on option 1. I selected 2 so it changed to the new version I installed.

Final step is to run the command below and get a similar entry as mine.

[ricardo@mybox]$ /usr/sbin/alternatives --display java
java - status is manual.
link currently points to /opt/jdk1.5.0_11/jre/bin/java
/usr/lib/jvm/jre-1.4.2-gcj/bin/java - priority 1420
slave keytool: /usr/lib/jvm/jre-1.4.2-gcj/bin/keytool
slave rmiregistry: /usr/lib/jvm/jre-1.4.2-gcj/bin/rmiregistry
slave jre_exports: /usr/lib/jvm-exports/jre-1.4.2-gcj
slave jre: /usr/lib/jvm/jre-1.4.2-gcj
/opt/jdk1.5.0_11/jre/bin/java - priority 2
slave keytool: (null)
slave rmiregistry: (null)
slave jre_exports: (null)
slave jre: (null)
Current `best' version is /usr/lib/jvm/jre-1.4.2-gcj/bin/java.


Now Eclipse. Eclipse keep using the old runtime everytime you create a new project.

To solve this when you create a project go to the JRE section and click on "Configure JREs" as shown on the image below.


Then on the following screen you click on add and complete the form with the details shown below (note that the libraries section will be auto completed once you selcted the home directory).


The final step is to check the new JRE and every new project will be using the Sun engine.



That is all, Good luck!


Much more information on the link below:
http://stanton-finley.net/fedora_core_5_installation_notes.html#Java

No comments: