Java Tutorial - Java Script : Installing Tomcat under Linux

Java Tutorial - Java Script :

Installing Tomcat under Linux


For evaluation purposes, it is sufficient to only install a personal copy of Tomcat within your Linux home directory. The steps for doing this are described briefly in the following list and in more depth in the sections following it.
1.       Download the compressed .tar archive.
2.       Check to make sure that the JDK is installed
3.       Create a deployment directory
4.        Extract the files from the archive
5.        Set the environment variables
6.       Add an administrator
7.       Start Tomcat

Step 1: Download the Archive
The archive file can be downloaded from the following URL: http://jakarta.apache.org/tomcat
The name of the archive varies according to the version number. For the purposes of illustration, we will assume that the name of the .tar archive file will be jakarta-tomcat.tar.gz and that it is located in your home directory.

Step 2: Check the JDK
You need to have a JDK installed to use Tomcat. To ensure that the JDK is installed and you are configured to use it, enter the following command: java –version This command should return a message like the following:
java version “1.4.1_01” Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01) Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode) Now, you need to ensure that the JAVA_HOME environment variable is set. The echo command can be used to do this. echo $JAVA_HOME This should print the path to the root directory where Java is installed. If it does not, then this environment variable will have to be set. The following shows how JAVA_HOME would be set on your system. This is dependent on how the JDK is installed your system and may need to be modified for your system. export JAVA_HOME=/usr/java/j2sdk1.4.1_01 Placing this line in the .profile file will make certain it is set each time you log into the system...

Step 3: Create the Deployment Directory
You want to install Tomcat into a directory located below your home directory. You will use the directory named jakarta/tomcat. You only need to create the jakarta directory for now. md Jakarta cd Jakarta

Step 4: Extract the Files
The following command extracts the .tar archive into a directory in your new jakarta directory. You will then rename the directory as tomcat. tar -zxvf ../jakarta-tomcat.tar.gz mv jakarta-tomcat tomcat

Step 5: Set Environment Variables
You need to set the environment variable CATALINA_HOME. This should be set to the directory where Tomcat has been installed. The following command does this. export CATALINA_HOME=$HOME/jakarta/tomcat If you add this command to the .profile file, then you won’t have to set it manually in the future. The following echo command can be used to check that CATALINA_HOME has been set properly. echo $CATALINA_HOME
Step 6: Set up an Administrator

You want to add an administrator password so you can use the administrationtool built into Tomcat. To do this you need to edit the file tomcatusers. xml. This file is found in the jakarta/tomcat/conf folder. Add the lines shown in bold in the following code.
<?xml version=’1.0’ encoding=’utf-8’?>
<tomcat-users>
<role rolename=”admin”/>
<role rolename=”manager”/>
<role rolename=”role1”/>
<role rolename=”tomcat”/>
<user username=”admin” password=”adminpasswd” roles=”admin,manager”/>
<user username=”both” password=”tomcat” roles=”tomcat,role1”/>
<user username=”role1” password=”tomcat” roles=”role1”/>
<user username=”tomcat” password=”tomcat” roles=”tomcat”/>
</tomcat-users
Step 7: Run Tomcat
Now, you are finally ready to start Tomcat and see if it works. The following command will start Tomcat:
cd $HOME/jakarta/tomcat/bin ./startup.sh You can test to make certain it is working by opening your browser and pointing it to: http://localhost:8080 Using the Mozilla browser on Linux, you should see the response shown in Figure 5.7.

You should also test to make sure that JavaServer Pages are working. To do this, click the JSP Examples link on the startup page or enter the URL: http://localhost:8080/examples/jsp/index.html This will provide a list of JSP examples that are installed in Tomcat. As mentioned earlier, we suggest that you try the snoop example and make sure it works. Snoop returns information about the HTTP request that invoked the page