Installing the Oracle (Sun) JDK on the default Amazon Linux Instance

Installing the Oracle (SUN) JDK on the default Amazon Linux Instance

Overview

Step 1: Download the Oracle Java JDK "RPM"

Step 2: Run the RMP Installer

Step 3: Run the "alternatives" program

Step 4: Set the JAVA_HOME for user and Root

Make JAVA_HOME part of the root environment variables

Step 5: Verify the Java Versions

Verify as the standard user:

Verify as the root user will use the correct version of Java

Step 6: Restart the eXist Server

Step 7: Verify that eXist is Using the Correct JDK

Step 8: Test the FOP SVG rendering

Overview

The current eXist software has been tested on the Oracle(Sun) Java Development Kit (JDK) but not extensively on the newer OpenJDK.  Unfortunately the OpenJDK is the default JDK available on the default Amazon Linux AMI and there are no "installers" that allow you to install the Oracle(Sun) JDK using the UNIX "yum" installation tool.  So as a result we must run a series of UNIX shell commands to reconfigure our Amazon Linux instance to make it reliable for eXist.

The following are the steps to change the default JDK on the default Amazon Linux AMI.  There are minor differences between the two JDKs but the Oracle(Sun) JDK is more mature and and currently supports a few more features.   For example if you use the XSLFO module to convert documents to PDF and you use SVG in your documents the fonts for rendering SVG images within PDF documents will not work with OpenJDK.

In this document the text you type is in a blue bold font.  The text returned by the UNIX shell is in a 10pt font.

Step 1: Download the Oracle Java JDK "RPM"

You must first know if you are running a 64bit or 32bin instance.  The following instructions assume a 64 bit instance.  Note that the Amazon "small" instances use a 32-bit hardware but the "micro" instance uses a virtual machine and 64-bit hardware.  

Here is a page that lists the current Java 6 release 31 binaries for Linux:

http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u31-download-1501634.html

The "rpm" is a binary file that will run like a Unix shell command.

$ wget -O jdk-6u26-linux-x64-rpm.bin http://download.oracle.com/otn-pub/java/jdk/6u26-b03/jdk-6u26-linux-x64-rpm.bin

or

Note that Oracle has changed this so that you must click the "yes I agree to license" license.

Here is the main web page:

http://www.oracle.com/technetwork/java/javase/downloads/jdk-7u4-downloads-1591156.html

Here is a sample RPM file link for the UNIX 32-bit system

http://download.oracle.com/otn-pub/java/jdk/7u4-b20/jdk-7u4-linux-i586.rpm

Then they will present the browser with a link and a URL you can use.  Copy this link into your shell.

kma-demo$ wget -O jdk-6u26-linux-x64-rpm.bin  http://download.oracle.com/otn-pub/java/jdk/6u26-b03/jdk-6u26-linux-x64-rpm.bin

--2011-12-23 15:32:49--  http://download.oracle.com/otn-pub/java/jdk/6u26-b03/jdk-6u26-linux-x64-rpm.bin

Resolving download.oracle.com... 204.245.162.34, 204.245.162.9

Connecting to download.oracle.com|204.245.162.34|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 80895878 (77M) [application/octet-stream]

Saving to: "jdk-6u26-linux-x64-rpm.bin"

100%[========================================================================================>] 80,895,878  20.3M/s   in 3.9s

2011-12-23 15:32:53 (20.0 MB/s) - "jdk-6u26-linux-x64-rpm.bin" saved [80895878/80895878]

Step 2: Run the RMP Installer

$ sudo chmod +x jdk-6u26-linux-x64-rpm.bin

$ ls -l

total 79084

-rwxrwxr-x 1 ec2-user ec2-user 80895878 May  5  2011 jdk-6u26-linux-x64-rpm.bin

$ sudo ./jdk-6u26-linux-x64-rpm.bin

Unpacking...

Checksumming...

Extracting...

UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).

  inflating: jdk-6u26-linux-amd64.rpm

  inflating: sun-javadb-common-10.6.2-1.1.i386.rpm

  inflating: sun-javadb-core-10.6.2-1.1.i386.rpm

  inflating: sun-javadb-client-10.6.2-1.1.i386.rpm

  inflating: sun-javadb-demo-10.6.2-1.1.i386.rpm

  inflating: sun-javadb-docs-10.6.2-1.1.i386.rpm

  inflating: sun-javadb-javadoc-10.6.2-1.1.i386.rpm

Preparing...                    ########################################### [100%]

   1:jdk                        ########################################### [100%]

Unpacking JAR files...

            rt.jar...

            jsse.jar...

            charsets.jar...

            tools.jar...

            localedata.jar...

            plugin.jar...

            javaws.jar...

            deploy.jar...

Installing JavaDB

Preparing...                    ########################################### [100%]

   1:sun-javadb-common          ########################################### [ 17%]

   2:sun-javadb-core            ########################################### [ 33%]

   3:sun-javadb-client          ########################################### [ 50%]

   4:sun-javadb-demo            ########################################### [ 67%]

   5:sun-javadb-docs            ########################################### [ 83%]

   6:sun-javadb-javadoc         ########################################### [100%]

Java(TM) SE Development Kit 6 successfully installed.

Product Registration is FREE and includes many benefits:

* Notification of new versions, patches, and updates

* Special offers on Oracle products, services and training

* Access to early releases and documentation

Product and system data will be collected. If your configuration

supports a browser, the JDK Product Registration form will

be presented. If you do not register, none of this information

will be saved. You may also register your JDK later by

opening the register.html file (located in the JDK installation

directory) in a browser.

For more information on what data Registration collects and

how it is managed and used, see:

http://java.sun.com/javase/registration/JDKRegistrationPrivacy.html

Press Enter to continue.....

Done.

Step 3: Run the "alternatives" program

The alternatives program are programs that allow you to easily switch between alternate versions of a package.

$ sudo alternatives --install /usr/bin/java java /usr/java/default/bin/java 20000

$ sudo update-alternatives --config java

There are 2 programs which provide 'java'.

  Selection        Command

-----------------------------------------------

   1               /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java

*+ 2               /usr/java/default/bin/java

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

Fix the symbolic links to the jre

$ sudo ln -s /usr/java/default/jre /usr/lib/jvm/jre

$ sudo ln -s /usr/share/java /usr/lib/jvm-exports/jre

Step 4: Set the JAVA_HOME for user and Root

Add the following line to the /etc/profile:

export JAVA_HOME=/usr/lib/jvm/jre

After you login you should be able to type:

$ sudo echo $JAVA_HOME

And it should return:

/usr/lib/jvm/jre

If it does not you will not be using the correct Java VM when you use "sudo" commands.

Make JAVA_HOME part of the root environment variables

If this does not work you must make the JAVA_HOME environment variable "sticky" for the root user.  This can be done by editing the file /etc/sudoers and adding the following line around line 70

Defaults   env_keep += "JAVA_HOME EXIST_HOME"

This will keep the environment variables permanently.

Step 5: Verify the Java Versions

Verify as the standard user:

$ java -version

java version "1.6.0_26"

Java(TM) SE Runtime Environment (build 1.6.0_26-b03)

Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)

Note that even though the word "Sun" or "Oracle" is not in this you shound NOT see the "OpenJDK" anywhere in the version text.

Verify as the root user will use the correct version of Java

$ sudo java -version

java version "1.6.0_26"

Java(TM) SE Runtime Environment (build 1.6.0_26-b03)

Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)

Step 6: Restart the eXist Server

I have an alias set up to restart the exist server called "restart-exist".  This is just a shorthand for running the /usr/local/bin/exist restart command as superuser.

$ restart-exist

Stopping eXist Native XML Database...

Stopped eXist Native XML Database.

Starting eXist Native XML Database...

Waiting for eXist Native XML Database...........

running: PID:23399

Here are my aliases:

$ alias

….

alias exist-status='sudo /usr/local/bin/exist status'

alias restart-exist='sudo /usr/local/bin/exist restart'

alias start-exist='sudo /usr/local/bin/exist start'

alias stop-exist='sudo /usr/local/bin/exist stop'

Step 7: Verify that eXist is Using the Correct JDK

Go to the "Admin Status" page at http://localhost:8080/exist/admin/admin.xql and you should see the following

Step 8: Test the FOP SVG rendering

For a full test that the correct fonts have been loaded you must enable the fop module and then run the "render-svg-text-test.xq" script supplied by your CMS rendering framework.

You should see the following output: