Alright, this is a very simple question. I just installed Tomcat 6 on my Mac to play around with it, and every tutorial I look at says the first thing to do to create a new web application is to add a line to the server.xml file with defines a new Context
. Fair enough. However, my question is, I don't see a line in there for the example web applications, so how do those work?
views:
40answers:
1The sample web applications use the default host defined in $CATALINA_HOME/conf/server.xml
:
<!-- Define the default virtual host
Note: XML Schema validation will not work with Xerces 2.2.
-->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
...
</Host>
Notice the appBase
attribute (which is defined relative to $CATALINA_HOME
). If you drop a .war
file in that folder, it will be auto-deployed as a context in the default host. Tomcat will dynamically create a context if none is defined in $CATALINA_HOME/conf/server.xml
(actually there are a couple of other places contexts can be defined too but that is outside the scope of this discussion).
So for example, if you drop a war file named mycontext.war
in $CATALINA_HOME/webapps
, you'll be able to reach it with your web browser at the url http://localhost:8080/mycontext/
(assuming you haven't changed the default port and autoDeploy settings that tomcat ships with). This is how the examples that ship with tomcat are set up.