Deploying Web Applications to Tomcat


Web application for Tomcat are usually distributed as a single Web Application Archive file. This makes shipping the application easy but it leaves the user asking “What do I do with this file?” and “Where do I put it on my server?” During these notes I will concentrate on installing the OpenLaszlo development platform for creating Internet rich applications but the techniques discussed apply to any Web Application deployed on Tomcat.

Format of the WAR file

The WAR file is similar to a Java JAR file. It is an archive that contains:

  • The web files (html, jsp, css) etc needed by the client’s browser. These go into the root of the archive
  • WEB-INF/web.xml – The Web Application Deployment Descriptor for your application. This is an XML file describing the servlets and other components that make up your application, along with any initialization parameters and container-managed security constraints that you want the server to enforce for you.
  • /WEB-INF/classes/ – This directory contains any Java class files (and associated resources) required for your application, including both servlet and non-servlet classes, that are not combined into JAR files. If your classes are organized into Java packages, you must reflect this in the directory hierarchy under /WEB-INF/classes/.
  • /WEB-INF/lib/ – This directory contains JAR files that contain Java class files (and associated resources) required for your application, such as third party class libraries or JDBC drivers.

Installing Tomcat

If you selected the default setting when you installed SuSE Linux then the Tomcat servlet container application will not be installed. Start YaST and select “Software” and “Software Management” for SuSE 9 users select “Install and Remove Software” (see figure 1).

In the search box enter “tomcat” and click on the “Search” button. For SuSE 10 users click on “Tomcat5”, “Tomcat5-Admin-Webapp” and “Tomcat5-Webapps”, for SuSE 9 users select “Jakarta-Tomcat” and “Jakarta Tomcat Examples” (see figure 2).

Click on the “Accept” button to proceed. The next screen will display a list of missing dependencies, click on the “Continue” button to install the necessary packages that will resolve these missing dependencies (see figure 3).

When prompted change CDs to install the servlet and dependent modules.

Once Tomcat has been installed you will need to start the application. From YaST select “System” and “System Services (Runlevel)” for SuSE 10 users or “Runlevel Editor” for SuSE 9 users (see figure 4).

Click on the Tomcat entry and press the “Enable” button. This should pop up a window showing you that Tomcat started properly (see figure 5). If it fails to start then examine the message displayed to see what has to be resolved before Tomcat will start. Usually some other service is already running on the default port 8080. In that case you will have to change the port used by Tomcat. Edit the file: “/usr/share/tomcat/conf/server/xml” and look for the section:

<!-- Define a non-SSL Coyote HTTP/1.1 Connector on port 8080 -->
   <Connector port="8080"
      maxThreads="150" minSpareThreads="25"
      enableLookups="false" redirectPort="8443"
      debug="0" connectionTimeout="20000"
      disableUploadTimeout="true" />

Change the “Connector port” to a port number not in use on your server and try restarting the Tomcat servlet.

If all goes well we can test Tomcat to see if is working. Start up your favorite browser and go to http://localhost:8080 (change the port number if you altered the default port number in server.xml).You should see the Tomcat startup page (see figure 6).

Tomcat Management

The Tomcat servlet can be managed manually but I wouldn?t recommend this approach. A simple mistake in any of the XML configuration files can. and often will, break the Tomcat installation. Instead, use the “Tomcat Management” link from the Tomcat startup page. SuSE Linux or Tomcat 4 users go to http://localhost:8080/manager/html (see figure 7).

Before the management page loads you will asked for a user name and password. These are not the same as the administrator?s user name and password for the Linux server. The opening page gives us a clue to the user name and password required:

“NOTE: For security reasons, using the administration webapp is restricted to users with role “admin”. The manager webapp is restricted to users with role “manager”. Users are defined in $CATALINA_HOME/conf/tomcat-users.xml.”

Start a console shell and edit “/usr/shared/tomcat5/conf/tomcat-users.xml” and add the line:

<user username="mytomcatuser" password="mypassword" roles="admin,manager"/>

Obviously, change the user name and password to suite your own requirements. Restart Tomcat to apply these changes. The easiest way to restart Tomcat is to type “rctomcat5 restart” from a command shell or “/etc/rc.d/tomcat5 restart”. Alternatively you can use the Runlevel editor in YaST. For SuSE Linux 9 users substitute “tomcat” for “tomcat5” in the above instructions.

Deploying the Application

At this stage you should be ready to install and run your web application. From the “Tomcat Web Application Manager” page, scroll down to the part labeled “WAR file to deploy”. Click on the “Browse” button and navigate to the Web Application WAR file that you want to install. Click on the “Deploy” button (figure 8). The Tomcat Web Application manager will unpack the WAR archive and put your application in the correct location for you.

After the Web Application Manager has finished deploying your application it should be ready for testing.

Using the Application Manager means that you do no have to stop and restart Tomcat server to make the application available. You will notice from the screen that your application is now a part of tomcat and from this page you can start, stop, restart and even undeploy (is that really a word? I can?t find it in any dictionary) your application (see figure 9).

Now that we have the OpenLaszlo development system installed, it is time to test it. Point the browser are http://localhost:8080/openlaszlo-3.3.3/ or click on the link for the OpenLaszlo system on the Tomcat Web Application Manager web page (see figure 10).

If you open up a shell and navigate to “/usr/share/tomcat/webapps/openlaszlo-3.3.3” you will see the files associated with the OpenLaszlo development system. All installed applications go into the web apps folder on the Tomcat server.

Figure 11 shows one of the sample applications created using the OpenLaszlo

This technique of adding web applications to Tomcat works on both SUSE Linux Enterprise Server versions 9 and 10 and Tomcat versions 4 and 5. As I said earlier, Tomcat can be configured by manipulating the various XML files provided with the server but a simple mistake can cause the system to stop functioning.

(Visited 1 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *

No comments yet