![]() |
![]() |
||||
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.
First, locate your webapps folder, this will be referred to as <webapps> below
Create a folder under the <webapps> folder (eg: /private-cgi-bin/tomcat/MyNewApp)
Tip: if this will be your main application for the website, call the application 'ROOT' (in capitals) instead of MyNewApp, to make it the ROOT application for your site.
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:
<webapps> /MyNewApp /WEB-INF
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:
<webapps> /MyNewApp /WEB-INF web.xml
This file is the Deployment Descriptor. It describes the application to Tomcat.
As soon as Tomcat notices the <appname>/WEB-INF/web.xml file inside the webapps folder, it will deploy the application automatically, and it will appear in the Tomcat Manager using the name from the <display-name> tag above. This is handled automatically by Tomcat's autoDeploy feature.
We will add a welcome page to show the application is working.
Create a file called /tomcat/MyNewApp/index.jsp 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:
<webapps> /MyNewApp index.jsp /WEB-INF web.xml
That's all there is to it! The application should have started automatically. This can be checked by browing to http://yoursite/MyNewApp.
You can also check the status of your new application Tomcat Manager.
If the application is not running, see Troubleshooting Application Deployment on Tomcat.
You can now add some JSP code to your index.jsp file, or make a new JSP file in the application root folder.
For Java Servlets, you will need to add some information in the web.xml file. This is covered in more detail at web.xml. See the <servlet> and <servlet-mapping> tags.