Install Java/Tomcat

How to Install Java and Apache Tomcat on a Centos 5 server;

Question:

How do I install Tomcat on Centos?

Answer:

In order to install Tomcat on Centos you first need to install Java. Both free and non-free packages are required for the installation. The non-free packages do not cost money however you must download them directly from Sun and agree to the license terms.

1) Install Build Packages

yum install rpm-build gcc-java jpackage-utils libXp

2) Download Java files:

Make a Directory to store the Java files:

mkdir /opt/Java

3) Download needed files to Java directory we created:

wget http://mirrors.sunsite.dk/jpackage/1.6/generic/non-free/SRPMS/jta-1.0.1-0.b.4jpp.nosrc.rpm
wget http://mirrors.sunsite.dk/jpackage/5.0/generic/non-free/SRPMS/java-1.5.0-sun-1.5.0.15-1jpp.nosrc.rpm

4) Download 2 files needed from Sun:

Go to http://java.sun.com/products/archive/ and half way down the page you will see JDK/JRE – 5.0 to the right of it in the drop down text box. Select “5.0 Update 15? and hit GO.
Select “Download JDK” and on the next page
Select platform: linux and then
Download the file jdk-1_5_0_15-linux-i586.bin to Directory /opt/Java

Then go to http://java.sun.com/products/jta/ and Select “Class Files 1.0.1B” and download the file to the directory /opt/Java

To install or build RPM Java files:

Copy files downloaded from Sun site to /usr/src/redhat/SOURCES :

cp /opt/Java/jta-1_0_1B-classes.zip /usr/src/redhat/SOURCES/
cp /opt/Java/jdk-1_5_0_15-linux-i586.bin /usr/src/redhat/SOURCES/

Build the RPM files and install:

rebuild — installs the named source package, and does a prep, compile and install. In addition, –rebuild builds new binary package

rpmbuild --rebuild /opt/Java/java-1.5.0-sun-1.5.0.15-1jpp.nosrc.rpm
rpm -Uvh /usr/src/redhat/RPMS/i586/java-1.5.0-sun-1.5.0.15-1jpp.i586.rpm
rpm -Uvh /usr/src/redhat/RPMS/i586/java-1.5.0-sun-devel-1.5.0.15-1jpp.i586.rpm

rpmbuild –rebuild –without javadoc /opt/Java/jta-1.0.1-0.b.4jpp.nosrc.rpm

rpm -Uvh /usr/src/redhat/RPMS/noarch/jta-1.0.1-0.b.4jpp.noarch.rpm

——————————————————
To install or update the Java VM RTE

Download the RPM file from:
32-bit Java: http://layer3.liquidweb.com/java/jre-6u2-linux-i586-rpm.bin
64-bit Java: http://layer3.liquidweb.com/java/jre-6u2-linux-amd64-rpm.bin
Make sure that you have the appropriate platform (ie x64_86 or x86)
Note: Please use the 32-bit version for Java applet and Java Web Start support.
1. Run the bin file and follow the on screen instructions (Press Q to exit the license)
After this is installed we need to update the symlink /usr/bin/java
cd /usr/bin/
rm -f ./java
ln -s /usr/java/jre1.6.0_02/bin/java java
To verify that this is installed run:
java -version
——————————————————

5) Install Apache Tomcat:

Install Apache Tomcat using yum:

yum install tomcat5 tomcat5-webapps tomcat5-admin-webapps

If you get an error:

***Error Missing Dependency: /usr/bin/rebuild-security-providers is needed by package java-1.4.2-gcj-compat***
a. Remove jpackage-utils: rpm -e jpackage-utils –nodeps
b. Disable the JPackage repo
c. Install from standard repos:

yum install jpackage-utils

Start Tomcat and Set to Start on Boot

Start Tomcat:

service tomcat5 restart

Set to Start on Boot:

chkconfig tomcat5 on

***if you get the error;
Starting tomcat5: /usr/bin/rebuild-jar-repository: error: Could not find xml-commons-apis Java extension for this JVM /usr/bin/rebuild-jar-repository: error: Some detected jars were not found for this jvm***

Run

yum install xml-commons-apis

this will install the missing extension.

Just a note regarding java;
Java usage will create an increased load on the server with a busy site, so expect to see this. (Java itself leaves a large memory footprint.)
This can usually be alleviated by incrementally increasing the RAM on the server as you see the load grow. Also make sure to have the hosting company optimize Apache for you to compensate for the increased load as well. (Apache optimization will aid only to a certain point, so do not expect to see large load drops, but very moderate changes.

g33kadmin

I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.