The web application space
December 31st, 2008
One of the easy options to start developing in tomcat is to start drooping files in the <Tomcat Home>/webapps/ROOT folder. However, if you are planning to create deployable applications (.war) it is better to create a web application space in to tomcat. The process is not complicated, I found great help reading and following the indication in these web articles: Deploying Web Applications to Tomcat, Demystifying Tomcat 4’s server.xml File, How to Create a Web Application in Tomcat Sever?
In summary what it is necessary to do is the following:
- Create a folder for you new application in the <Tomcat Home>/webapps/ folder. Lets call it ‘newapp’.
- Inside newapp create the folder ‘WEB-INF’.
- Inside WEB-INF create the folders: classes and lib.
- Also create a file called ‘web.xml’ and put the following text in it:
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd"> <web-app> </web-app>
- Open to edit the file <Tomcat Home>/conf/server.xml and add the node <Context path=”/newapp” docBase=”newapp” debug=”0″ reloadable=”true” /> as a child of the node <Host> and save it.
- For testing purposes create a file in <Tomcat Home>/webapps/newapp called test.jsp with this code in it:
<% String message="Hello world!"; %> <%= message %>
- Open you favorite internet navigator go to http://localhost:8080/newapp/test.jsp
- You have now a new web application space in tomcat.
It is possible to have many web application spaces in tomcat.