I've recently purchased and going through the Servlet and JSP book written by Budi Kurniawan. I just come to the part in chapter one where I deploy and invoke a servlet. I'm using the example app01a directory and I placed it under Tomcat's webapps directory. I also created an app01a.xml file under localhost. I was able to successfully invoke the servlet once I started Tomcat.
My question is, if an app is located under the webapps directory, do you need to create the xml context file? I removed it from localhost and restarted Apache and everything still worked fine.
You dont need to create a context decriptor yourself unless you want to define specific resources related to your web-application or change the default context path etc. As you are in your initial learning phase, I would suggest not to get in the details of that right now, as it would get you confused, and instead focus on getting important base concepts first.
Do not worry about context descriptors as on startup, Tomcat will create one for every web-application present in the web-apps directory if a context descriptor does not exist already.
This is a small piece of information taken from the tomcat docs, which will give you some idea on what happens on startup.
The following deployment sequence will occur on Tomcat startup in that case:
1) Any Context Descriptors will be deployed first.
2) Exploded web applications not referenced by any Context Descriptor will then be deployed. If they have an associated .WAR file in the appBase and it is newer than the exploded web application, the exploded directory will be removed and the webapp will be redeployed from the .WAR
3) .WAR files will be deployed
Note again that for each deployed web application, a Context Descriptor will be created unless one exists already.
Joined: Feb 29, 2012
subject: Is a context xml file or server.xml edit required if servlet application is in webapps