Monday, August 2, 2010

Tomcat: Troubleshoot the Tomcat?

In order to run Tomcat, you will need to install JDK and set the JAVA_HOME environment variable to identify the location of the JDK environment on your system. I have chosen to use JDK 5.0.

1. You can download JDK 5.0 at http://java.sun.com/j2se/1.5.0/download.jsp.

2. Click on Download JDK 5.0 Update 6 to go to the download page.

3. Click Accept to accept the license agreement.

4. Next choose the Linux self-extracting file. This is the download for the self-extracting binary file rather than the rpm.

5. Download to your preferred download directory. Change to that directory and make it executable by executing the following command:

chmod +x jdk-1_5_0_06-linux-i586.bin

6. Now execute the file:

./jdk-1_5_0_06-linux-i586.bin

7. You should now have a new directory called j2sdk1.5-sun. Now move this directory to the location where it should be run. I chose /usr/lib/.

mv j2sdk1.5-sun /usr/lib

8. Now create a symbolic link called jdk to JAVA_HOME by the following command. This allows you to easily switch back and forth between different jvms should you ever need to

cd /usr/lib

ln -s j2sdk1.5-sun jdk

8. Now we need to set the JAVA_HOME environment variable. Add the following at the end of /etc/profile just after export PATH.

JAVA_HOME="/usr/lib/jdk"

export JAVA_HOME

/etc/profile is executed at startup and when a user logs into the system. In order to update the environment you will need to log out and log back in to the system.

10. Check to make sure JAVA_HOME is defined correctly by executing the command below. This should report the location of the Java SDK which should be /usr/lib/jdk.

echo $JAVA_HOME

11. Now test Java with the following command. You should be returned with /usr/bin/java. If so, you have successfully completed this section.

which java
export JAVA_HOME=/usr/java/jdk1.6.0_15
export PATH=$PATH:$HOME/bin:/bin:/usr/local/bin:/usr/bin:/usr/java/jdk1.6.0_15/bin/


Setting Tomcat

Download the binary version to your preferred download directory from here: http://tomcat.apache.org/download-55.cgi. Choose the tar.gz from the core section for 5.5.15.
Now change to that directory and extract the files using the following command:

cd /mydownloads (be sure to change to your download directory)

tar xvzf apache-tomcat-5.5.15.tar.gz

You should now have a new directory called apache-tomcat-5.5.15. Now move this directory to the location where it should be installed. Again, I chose /usr/lib/. Note that this location will be referred to as CATALINA_HOME in the Tomcat documentation.

mv apache-tomcat-5.5.15 /usr/lib

Next change to the /usr/lib/ directory.

cd /usr/lib

Now create a symbolic link called apache-tomcat to CATALINA_HOME by the following command.

ln -s apache-tomcat-5.5.15 apache-tomcat

[root@linuxguy bin]# echo $CATALINA_HOME
/usr/lib/apache-tomcat
[root@linuxguy bin]# pwd
/usr/lib/apache-tomcat/bin



[root@linuxguy bin]# ./startup.sh
The BASEDIR environment variable is not defined correctly
This environment variable is needed to run this program


How to troubleshoot?


[root@linuxguy bin]# chmod +x *.sh
[root@linuxguy bin]# ./startup.sh
Using CATALINA_BASE: /usr/lib/apache-tomcat
Using CATALINA_HOME: /usr/lib/apache-tomcat
Using CATALINA_TMPDIR: /usr/lib/apache-tomcat/temp
Using JRE_HOME: /usr/java/jdk1.6.0_15
Using CLASSPATH: /usr/lib/apache-tomcat/bin/bootstrap.jar
[root@linuxguy bin]#
[root@linuxguy bin]#