A Funny Java Flavoured Look at the World

Wednesday, August 09, 2006

Idiots guide to installing Java 5 and Tomcat 5 on Linux Red Hat

This website was very useful for easy to use instructions on installing Tomcat 5 and Java 5. It has a load of stuff before the tomcat installation instructions but I just ignored them and went straight to the main event

The bit I wanted from the guide is down at the bootom of this email and well worth checking out

I had a bit of a problem as well because I needed to have OC4J installed and using Java 1.4 and I need Java 5 and because of Java 5 I needed to install Tomcat 5. The last thing I needed to do to add a bit more interest is to put it on port 8181 just in case there were any oracle apps listening and hogging 8080.

Installing Java was a fairly straight forward, I downloaded the latest Java 5 JDK and then ran the file, firstly it unzipped it and then I doubled clicked on that and it installed Java 5 into the, right next door to Java 4 but without doing any damage to it.

/usr/java/jdk1.5.Untitled 10_07

Tomcat was a bit different (for a windows developer) the download basically just you a gz file and when you clicked on it, it just produced an unzipped directory structure of tomcat.

So on the advice of the article I copied into usr/local/tomcat

I had a problem now that OC4J wanted the JAVA_HOME variable to be pointing to JAVA 1.4 and the tomcat mentioned using JAVA_HOME all over it's start up files and in other places.

The JAVA_HOME variable is set up in the profiles file which is here

/etc/profiles/

and this is what I had in there, I copied it in the bottom

export JAVA_HOME=/usr/java/j2sdk1.4.2_04
export PATH=$JAVA_HOME/bin:$PATH

export CATALINA_HOME=/usr/local/tomcat
export JAVA5_HOME=/usr/java/jdk1.5.0_07
export PATH=$JAVA5_HOME/bin:$PATH

export JRE_HOME=/usr/java/jdk1.5.0_07
export PATH=$JRE_HOME/bin:$PATH

I changed the JRE_HOME because tomcat mentioned it and I didn't think OC4J did (well I didn't know what I was doing is the real answer)

So I set up an environment variable in windows called JAVA5_HOME and then restarted Linux. I tested the my environment variables were working by going into a terminal and then doing $JAVA5_HOME , you just put a dollar sign ahead of any of the environment variables and it echo's it out.

Changing port 8080 to 8181

This setting is found in this file

/usr/local/tomcat/conf/server.xml

if you search for 8080 and then change this to 8181 or another port you fancy.

I tried to start tomcat and wondered how I would do this and found that running the sh (shell script) startup.bat does the trick, so once again I went to the terminal

cd /usr/lib/apache-tomcat/bin

sh startup.sh

and to shutdown it's

cd /usr/lib/apache-tomcat/bin

sh shutdown.sh

This of course didn't work because they were using JAVA_HOME Reference. You need to go edit these two sh files and change JAVA_HOME to JAVA5_HOME. Actually you probably won't find a reference to JAVA_HOME in the startup and shutdown shell scripts but you will find one in the Catalina.sh shell script. The Catalina shell script is the one that sets up all the variables and memory settings and then calls the startup and shutdown shell scripts.

Then I started it and Tomcat worked but it was having problems, for some reason it hadn't put a log folder in. So in these directory I created a folder called logs

/usr/local/tomcat

I then tried to log in to the admin console and the admin user didn't exist!!!! I edited

/usr/local/tomcat/conf/tomcat-users.xml

and added





restart linux, have a cup of tea. Come back and start up Tomcat using some sh startup.sh power and hallaluh Tomcat is up and running and I can snuggle up in the safe bosum of the Tomcat manager.

Below is a section from http://www.howtoforge.com/apache2_tomcat5_mod_jk_p2 and from the first page where it tells you how to install Java and Tomcat and start tomcat.

Installing JDK (Java Development Kit)

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

Installing Tomcat

In this section you will download and install Apache Tomcat 5.5.15. For this particular setup, there is no need to build the package from source, we will download the binary version.

1. 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.

2. 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

3. 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

4. Next change to the /usr/lib/ directory.

cd /usr/lib

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

ln -s apache-tomcat-5.5.15 apache-tomcat

This will save you from having to make changes to startup and shutdown scripts each time you upgrade Tomcat and if you so desire, it also allows you to keep several versions of Tomcat on your system and easily switch amongst them.

6. You should now be able to start and stop Tomcat from the CATALINA_HOME/bin directory. If you are using another shell other than the bash shell you will nee to add sh to the beginning of the command. You should now be able to test that Tomcat is installed by starting it and opening your browser and entering http://localhost:8080 into your browser. Port 8080 is the default port for Tomcat and can be easily changed in the /usr/lib/apache-tomcat/conf/server.xml file. (We will work with this file later on.) If you plan to access this page remotely, be sure to forward the respective port to your server’s IP address within your router. You should now see the Tomcat welcome page that contains links to Tomcat documentation as well as sample JSP/Servlet scripts. Verify that Tomcat is running by executing some of the examples found on the welcome page.

cd /usr/lib/apache-tomcat/bin

sh startup.sh

To shutdown the server, you will need to execute the following command. Feel free to try it, but for now we will leave Tomcat running.

sh shutdown.sh

0 Comments:

Post a Comment

<< Home