Install the latest Java 7 JDK on Ubuntu Linux Server 10.04 without apt-get

I was trying to set up Apache Tomcat on an older server running Ubuntu 10.04 and noticed that Java wasn’t actually installed by default. Also, the licensing agreement with Oracle seems to have changed and it is no longer possible to just use apt-get to install it. You have to manually accept the licensing agreement so even “wget” wont work any more (you just get a “download-fail-XXXXXXX.html” file instead.

First up, you have to go to the Java JDK download page and manually accept the licensing agreement. This must be done from a PC with a UI and a browser so no “wget”. You need to get the correct version, which in my case was the x86 tar.gz version. When this is downloaded you should have a “jdk-7u9-linux-i586.tar.gz” file which then needs to be copied to your Ubuntu server (I copied to my user’s home directory).

Now you have the file on your Ubuntu server you can extract it using:

tar -xvf jdk-7u9-linux-i586.tar.gz

This should give you a directory “jdk1.7.0_09″ which we need to move to somewhere sensible such as “/usr/lib/jvm/jdk1.7.0_09″:

sudo mv jdk1.7.0_09 /usr/lib/jvm/jdk1.7.0_09

Now we need to set up a symbolic link so that we can run Java from everywhere:

 sudo ln -fs /usr/lib/jvm/jdk1.7.0_09/bin/java /usr/bin/java

Now check that Java is all installed correctly by checking the version using:

java -version

Which in this case should give:

java version “1.7.0_09″
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) Client VM (build 23.5-b02, mixed mode)

Now you can set up your JAVA_HOME variable at a system level so other applications can use Java by editing “/etc/environment”:

sudo nano /etc/environment

Now add the following line to point to your newly installed Java:

JAVA_HOME=/usr/lib/jvm/jdk1.7.0_09

Now if you open up a new session (not your currect session) and type “echo $JAVA_HOME” you should see the path “/usr/lib/jvm/jdk1.7.0_09″ which means the variable has been set correctly.

Running Web Applications on Oracle OC4J and Solaris

I reached the stage where I can deploy the example web application from Oracle on my own standalone Oracle Containers for Java EE (OC4J) installation running on Solaris. There were a couple of hurdles before I got this far, one of which is a known bug with the Oracle Application Development Framework (ADF). Now that my Solaris install is set up I should be able to deploy applications written on my local machine (a Windows XP install) to my OC4J server using Oracle Jdeveloper.

First up I downloaded the latest version of the OC4J standalone install and extracted it to “/export/home/OC4J”. I set the “J2EE_HOME” environment variable to “/export/home/OC4J/j2ee/home” and made sure “JAVA_HOME” was set to “/usr/java”.

Next I tested the install by downloading the “Hello World” .jsp page from Oracle. After making sure this was working ok by placing it in “/export/home/OC4J/j2ee/home/default-web-app” and going to “http://serveraddress:8888/helloworld.jsp” I was ready to try installing an actual web application.

I followed the instructions from Oracle for deploying a web application. In short this requires you to enable the “oe” user in Oracle, set up a connection to your Oracle database and OC4J server in Oracle Jdeveloper and set up deployment projects for the example web application. This is all covered in the tutorial.

I tested the application on my local machine where it worked fine so I thought it could easily be deployed. I clicked “Deploy to OC4J” on the “OrderEntryApplication.deploy” .EAR file and the deployment failed. I tried using the web interface at “http://serveraddress:8888/em” to deploy the .EAR file manually and got the same error (sorry I didn’t record exactly what it was).

Next up I googled and found that you need the Oracle ADF installed on your OC4J server in order to run web applications. It isn’t installed by default in the OC4J standalone install so you need to install it manually. I read a few forum posts that said you could install ADF by just copying some .jar files across to your OC4J install but decided to do it the “proper” way as suggested by Oracle. I installed Jdeveloper on my Solaris box by downloading it and extracting to “/export/home/jdevstudiobase10134″ then started it by running “/export/home/jdevstudiobase10134/jdev/bin”. I shut down my OC4J server first as required and clicked “tools -> ADF Runtime Installer -> Standalone OC4J…” in Jdeveloper and went through the wizard to install the ADF runtime components.

This should have been fine but when I went to start the OC4J server up again I got an error:

Error initializing server: Shared library “oracle.ws.jaxrpc” could not be found.

According to this forum post this is a bug and the workaround has even been included in the 10.1.3.x release notes addendum. To fix it you need to go into your “J2EE_HOME/config/server.xml” and remove the two references to the offending library by deleting this line twice:

<import-shared-library name=”oracle.ws.jaxrpc”/>

Now when you start up the OC4J server again it will start and you can visit your web application. One final thing, if following the tutorial make sure you visit “http://servername:8888/OrderEntry/faces/index.jsp”. I missed out the “/faces/index.jsp”, if you miss out the “faces” you get a server 500 error (the server doesnt know to use Java Server Faces) and if you miss out the “index.jsp” the link on the first page doesnt go anywhere!

Next step is to write a custom application to display, edit and add data in an Oracle database schema. I will be using Enterprise Java Beans for data objects and Java Server Faces for the front end on top of JSP. Still a fair way to go but at least now we can create and deploy applications using Oracle Jdeveloper.

Setting Up & Starting Apache and Tomcat on Solaris 10 x86

Apache, Java and Tomcat are all installed by default in my copy of Solaris 10 x86, I assume this is the same for all versions of Solaris. I was dreading compiling Apache and Tomcat from source and was even considering installing the package from Blastwave.org. Luckily I googled a bit more and soon realised everything was installed by default, which is actually a bit obvious when you think about it.

Thanks to a random bug report page on opensolaris.org requesting an addition in documentation I got straight to the answer. I had to add an extra step in to add the required environment variables (which are now sitting in my “profile” file to be loaded each time). I’ve compressed the information a bit here but these are the steps I took to start Apache and Tomcat:

First add the two environment variables JAVA_HOME and CATALINA_BASE (for Tomcat) to your “/etc/profile” file or current session using usual “export” command:

export JAVA_HOME=/usr/java

and

export CATALINA_BASE=/var/apache/tomcat

Now you need to make sure the config files for both Apache and Tomcat exist with the right filenames. Luckily there are example config files included with both so you can just rename/copy these config files:

cp /etc/apache2/httpd.conf-example /etc/apache2/httpd.conf

cp /var/apache/tomcat/conf/server.xml-example /var/apache/tomcat/conf/server.xml

Now you can start up Apache:

svcadm enable apache

Now make a symbolic link to point the Tomcat “conf” directory to the Apache Tomcat “conf” directory (just to make sure config files come from the right place):

cd /usr/apache/tomcat

ln -s /var/apache/tomcat/conf conf

Now last of all, start up the Tomcat server using the startup.sh script in the Tomcat “bin” directory:

/usr/apache/tomcat/bin/startup.sh

Now you have both Apache and Tomcat running (on ports 80 and 8080 respectively). The home directory for Apache, where the html documents etc are stored, is located at “/var/apache2/htdocs/”. The home directory for Tomcat is at “/var/apache/tomcat/webapps/ROOT”.

Interestingly the test page for Tomcat at “http://localhost:8080″ states the environment variable as “$CATALINA_HOME” and not “$CATALINA_BASE” as I used. My Tomcat seems to be perfectly happy and I can run the sample applications so I guess you don’t need to worry about this.

UPDATE:

If you have installed Oracle you can use Oracle’s own web application server (OC4J) at “http://localhost:1158″. There is a default page here with links to documentation etc. I’ll write more on using this once I figure out how to do dev work in Windows and push it to our Solaris installs.