Sunday, March 20, 2011

Install Java 1.6 and Tomcat 6 under Ubuntu

I have installed Java und Tomcat on my VPS http://www.fractalsoft.net many times but never noted necessary steps. Here some helpful infos.

1) Issue following command to find out current jdk version in apt-get
apt-cache search jdk

2) Install java JRE with apt-get install
sudo apt-get install openjdk-6-jre

3) Set environment variable JAVA_HOME. Copy following statement and append to /etc/profile or .bashrc
export JAVA_HOME="/usr/lib/jvm/java-6-openjdk;"

4) Install Tomcat 6
sudo apt-get install tomcat6 tomcat6-admin tomcat6-common tomcat6-user tomcat6-docs tomcat6-examples

5) Change tomcat server to run on port 80 in
/var/lib/tomcat6/conf/server.xml (symbolic link) or etc/tomcat6/server.xml

7) Start tomcat server sudo /etc/init.d/tomcat6 start
Stop tomcat server sudo /etc/init.d/tomcat6 stop
Restart tomcat server sudo /etc/init.d/tomcat6 restart
Get tomcat server status sudo /etc/init.d/tomcat6 status

8) To enable admin web based features add the following lines to
/etc/tomcat6/tomcat-user.xml

<role rolename="manager"/>
<role rolename="admin"/>
<user name="admin" password="admin" roles="manager,admin"/>

Manager app http://www.fractalsoft.net/manager/html has now user / pwd = “admin”.

9) Adjust default Tomcat page below /var/lib/tomcat6/webapps/ROOT/index.html if nessesary.

Edit: If you get this exception
SEVERE: Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener
java.lang.ExceptionInInitializerError
...
Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission com.sun.aas.installRoot read) at java.security.AccessControlContext.checkPermission(AccessControlContext.java:342)
...
and the deployte web application doesn't start, set TOMCAT6_SECURITY=no (instead of yes) in the file /etc/init.d/tomcat6. Restart your Tomcat after that (login via ssh username@hostname and call sudo /etc/init.d/tomcat6 restart). Thanks to this post from ICEFaces forum!

2 comments:

  1. Thanks Oleg. Setting up Lucene and Solr and needed to get Tomcat and Java so this very useful

    ReplyDelete
  2. Thanks for the guide.

    Just a note:

    In step 3 you should remove the ";" at the end. If you use it there, you wont be able to start tomcat correctly.

    Although this step isn't really necessary because using:

    "sudo apt-get install tomcat6 tomcat6-admin tomcat6-common tomcat6-user tomcat6-docs tomcat6-examples"

    Automatically defines the JAVA_HOME for all users.

    ReplyDelete

Note: Only a member of this blog may post a comment.