Metawerx Java Hosting Small Logo

Deploying a new application with Tomcat

Author: Neale Rudd, Metawerx

Date: 27-Sep-2006

This is a short tutorial on creating a new application on Tomcat.

It assumes the site is hosted with Metawerx, but will work elsewhere as long as you can find your webapps folder, have the Tomcat Manager installed, or can manually reset the JVM if necessary.

Create the folder structure for the application

First, locate your webapps folder, this will be referred to as <tomcat> below

  • At Metawerx, this is located at /private-cgi-bin/tomcat
  • On a fresh tomcat installation, this is located at <path you installed tomcat to>/webapps

Create a folder under the webapps/tomcat folder (eg: /private-cgi-bin/tomcat/MyNewApp)

Create a WEB-INF folder in the new folder (eg: /private-cgi-bin/tomcat/MyNewApp/WEB-INF)

Your application folder structure should now look like this:

<tomcat>/MyNewApp/
<tomcat>/MyNewApp/WEB-INF/

Add a web.xml file

Create a new file in WEB-INF called web.xml, containing the following:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
     version="2.4">

    <display-name>My First App</display-name>
    <description>This is my first application</description>

</web-app>

Your application structure should now look like this:

<tomcat>/MyNewApp/
<tomcat>/MyNewApp/WEB-INF/
<tomcat>/MyNewApp/WEB-INF/web.xml

As soon as Tomcat notices the */WEB-INF/web.xml file inside the tomcat folder, it will deploy the application, and it will appear in the Tomcat Manager using the name from the <display-name> tag above.

Add a welcome page

Create a file called /tomcat/MyNewApp/index.htm using the following content:

<h1>My First App</h1>
<p>This is an application running on Tomcat</p>

Your application structure should now look like this:

<tomcat>/MyNewApp/
<tomcat>/MyNewApp/index.htm
<tomcat>/MyNewApp/WEB-INF/
<tomcat>/MyNewApp/WEB-INF/web.xml

Test

That's all there is to it! The application should have started automatically. This can be checked in the Tomcat Manager.

  • If it says true in the running column, you will now be able to access your new application as http://yoursite/MyNewApp
  • If it says false, there is an error in your web.xml file. Check that it contains the content from above.

To write some JSP, try renaming index.htm as index.jsp, or make a new file, then add some JSP code to it.

For Java Servlets, you will need to add some information in the web.xml file. This is covered in more detail at web.xml.

navigation
metawerx specific
search
Share
tools
help

referring pages
...nobody

Share