Monday, November 19, 2012

Installing Oracle Java and Tomcat on Ubuntu Server 12

Ubuntu Server comes with only a command line console so the usual GUI tools are unavailable.  You instead get to Java and Tomcat by hand. Oracle installations require the addition of another apt repository because they are license restricted from the Linux point of view.

Install Java

Enter the following commands into the VMWare visible console.
  1. Ubuntu server doesn't include add-apt-repository so first install that
    sudo apt-get install software-properties-common
    Enter "Y" if prompted.
  2. Add the repository that contains Oracle information
    sudo add-apt-repository ppa:webupd8team/java
    Press "Enter" to continue.
  3. Update the list of available packages
    sudo apt-get update
  4. Install Oracle 7
    sudo apt-get install oracle-java7-installer
    Enter "Y" and click on "<OK>" to accept the license
  5. Verify Java is installed by running
    java -version
You can set the JAVA_HOME for all processes by adding a adding a JAVA_HOME entry in /etc/environment.  You have do this with escalated privileges/sudo. I added this:
    JAVA_HOME=/usr/lib/jvm/java-7-oracle

Install Tomcat

Tomcat requires java so you must have some version installed as shown above.
  1. Install the Tomcat app server using apt-get
    sudo apt-get install tomcat7 tomcat7-admin ufw 
    libtcnative-1
  2. Install the Apache web server using apt-get This is optional for just hacking around in tomcat but is recommended for real production systems.
    sudo apt-get install apache2 libapache2-mod-jk 
  3. And now install the MS SQL Server, MySql and Postgresql java drivers if you are going to want them for your app-server installation
    sudo apt-get install libjtds-java libmysql-java libpg-java 
  4. Groovy is cool so install just because
    sudo apt-get install groovy
  5. Edit /etc/default/tomcat7 and set the JAVA_HOME to /usr/lib/jvm/java-7-oracle

Additional Configuration

Reconfigure the Apache mod-jk plugin that talks to Tomcat if you installed Apache2 in the previous section.
  1. Edit /etc/libapache2-mod-jk/workers.properties
  2. Change workers.tomcat_home to be point to tomcat7 instead of tomcat6
    workers.tomcat_home=/usr/share/tomcat7
  3. Change the default java version to point to the oracle JDK
    workers.java_home=/usr/lib/jvm/java-7-oracle
Restart the servers to pick up the changes

Verify 

  • Restart tomcat7 to pickup the changes
    sudo service tomcat7 restart
  • Verify the services running by hitting the tomcat server on port 8080 with your browser http://<ip>:8080/
  • Restart apache2 if installed
    sudo service apache2 restart
  • Verify the web server is running through the browser by requesting on port 80 http://<ip>
  • Verify they web server and tomcat are wired together using the link below

Credits

I was able to glean useful information on this topic from the following web sites.
  • http://www.ubuntugeek.com/how-to-install-oracle-java-7-in-ubuntu-12-04.html
  • http://magnus-k-karlsson.blogspot.com/2012/04/how-to-set-javahome-environment.html
  • https://wiki.umn.edu/Main/Tomcat7ServerOnUbuntuServer12_04LTS
  • http://thetechnocratnotebook.blogspot.com/2012/05/installing-tomcat-7-and-apache2-with.html

1 comment:

  1. Thanks!
    I skipped the groovy part, but I'm using that for another project. ;-)

    ReplyDelete