Sunday, November 25, 2007

Java EE SDK Installation Instructions

For as long as this link works, its a good generic reference for anyone wanting to update their JRE in Fedora/Linux. The steps below are specific to installing Sun's Java EE SDK (inclusive of JDK and JRE 1.6.0_06) on Fedora Core 6 32-bit i386. Should you be able to succesfully complete the following steps, you shall have the most enviable Java setups around. Here's how you go about it:

Before we begin, there are a few things you need to know. Whenever I mention something like:

$cd /opt

..it means that the command cd /opt must be typed at the prompt (so called as the dollar prompt) in the Terminal (that is Applications > Accessories > Terminal). Don't worry, you won't see a dollar sign in the terminal, but its just a convention of writing. Note that you must not type the dollar sign while entering the command.

Secondly, there is no such thing as a registry, in Linux. So you don't have to 'install' applications using an installer. You will generally get a .tar.gz or a .zip file from the download sites. These files must be simply extracted, and the resulting folder must be copied to any location of your choice. However, by convention, such folders are copied into /usr/lib/ directory under your file system. (The file system can be accessed from Applications > System Tools > File Browser). However, since there is no installation, some manual configuring effort is required. This effort is largely context dependent, and will vary as per:
  1. Distribution of Linux (Fedora, RedHat, Ubuntu, Debian, Mandriva, Gentoo.....)
  2. Version of distribution (Fedora 8, RedHat 10.....)
  3. The hardware platform for the distribution (i386 in my case, for Intel 32-bit processors)
  4. Application version you've downloaded
  5. Where you've saved (or subsequently copied) the extracted folder
Thirdly, when performing setup operations, you must always login as root.

Now, with a basic understanding of these things, lets get to the real thing:

Stage 1: Downloading the correct file, to the correct place
  1. Go to http://java.sun.com
  2. Select Downloads > Java EE
  3. Click on Download with JDK
  4. Accept the License Agreement
  5. Click on the link to Java EE SDK 5 Update 3 under Linux platform
  6. If you are using Firefox with default settings, the java_ee_sdk-5_03-linux.bin file will get downloaded to your Desktop
  7. Once done, copy the bin file to /opt (under your File System)
Stage 2: Installing the EE Server
  1. Open Applications > Accessories > Terminal
  2. $cd /opt
  3. $chmod +x java_ee_sdk-5_03-linux.bin
  4. $./java_ee_sdk-5_03-linux.bin
  5. Now, Java's GUI installation will begin.
  6. Proceed through the installation normally
  7. At the end, click on Start Server. If the installation proceeded succesfully, you should see a "Your server is up and running" page when you type http://localhost:8080/ in your browser
  8. Also, a SDK directory will be created under /opt
This completes half the story, that is, you built the environment. But still, other applications don't know of its presence, and, in my opinion, you should make it loud and clear! So here's what you do:

Stage 3: Setting up environment variables
  1. Open Applications > Accessories > Text Editor
  2. Copy paste the following things in a new (blank) file:
export JAVA_HOME=/opt/SDK/jdk
export JRE_HOME=/opt/SDK/jdk/jre
export PATH=$JAVA_HOME/bin:$PATH
export J2RE_HOME=/opt/SDK/jdk/jre
export PATH=$J2RE_HOME/bin:$PATH

Stage 4: Configuring the environment for use throughout Fedora
  1. Now save the file as java.sh in /etc/profile.d under your File System
  2. Back, to the terminal, do the following things:
  3. $source /etc/profile.d/java.sh
  4. $which java
  5. If you have proceeded correctly upto this stage, you should see /opt/SDK/jdk/jre/bin/java as the result.
  6. Proceed ahead ONLY IF you get this result. Else, you've gone wrong and must retrace. There's no point in moving forward if you don't get this result.
  7. Now, continue typing in terminal with the following commands:
  8. $usr/sbin/alternatives --install /usr/bin/java java /opt/SDK/jdk/jre/bin/java 2
  9. $usr/sbin/alternatives --config java
  10. Type 2 and hit enter
  11. $java -version
  12. If installation is complete, it should give the following result:
java version "1.6.0_03"
Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode)

Stage 5: Installing the JRE plugin for Firefox

Now, the final stage remains that of hooking up the JRE with your browser. Assuming you have correctly installed Mozilla Firefox 2.0.0.9 in /usr/lib/firefox do the following:

$ln -s /opt/SDK/jdk/jre/plugin/i386/ns7/libjavaplugin_oji.so /usr/lib/firefox/plugins/libjavaplugin_oji.so

Note that the entire statement above is on a single line, without hitting anywhere in between.

This will complete the entire installation procedure. I know its long and tedious, but trust me, its well worth the effort.

5 comments:

Anonymous said...

Hi :)

This is a brilliant guide! Thankyou, I have been bashing my head trying to figure this out :)

I am installign on debian, so there was a little bit of 'thinking' involved, but no too much. Everything seemed to work up until the last part:

root@EITdebian:/# /usr/sbin/update-alternatives --install /usr/bin/java java /opt/SDK/jdk/jre/bin/java 2
root@EITdebian:/# /usr/sbin/update-alternatives --config java
There are 3 alternatives which provide `java'.

Selection Alternative
-----------------------------------------------
1 /usr/bin/gij-wrapper-4.1
*+ 2 /usr/lib/jvm/java-6-sun/jre/bin/java
3 /opt/SDK/jdk/jre/bin/java

Press enter to keep the default[*], or type selection number: 2
Using `/usr/lib/jvm/java-6-sun/jre/bin/java' to provide `java'.
root@EITdebian:/# java --version Unrecognized option: --version
Could not create the Java virtual machine.
====================

I can not find any mention of this elsewhere. Are you aware of any possibilities here?

Thankyou again :)

Please reply to ghostsblood@gmail.com :)

Anonymous said...

please ignore my previous post. I needed only one hyphen on the version flag.

Regards

Anonymous said...

Hi

I just finished installing java in my Centos5 server. You made such a great guide and very easy to follow.
Thanks a lot.

---
ma

T Alrahem said...

excellent guide.
on ubuntu, you would use 'update-alternatives'.

the browser plugin however needs tweaking.

Unknown said...

On Ubuntu, when starting the GUI installation, if you get a blank screen, disable compiz.
My 2¢