• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
  • Tim Holloway
  • Carey Brown
  • salvin francis

Can I deploy a Servlet differently?

Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am preparing for the SCWCD and just in the first few pages of HFSJ. I deployed a servlet using Tomcat. But there is a doubt that bugging me a lot.

Whenever we deploy a webapps , we need to make a entry into the server.xml. Can it be more dynamic .Actually I am compiling the classes in the separate directory and putting it to the Tomcat /webapps folder with the help of the ANT build Script.

Suppose I created a Webapps and directly put the classes file in the Tomcat home and restart it, can able to find the webapps to be working, without always making an entry to the server.xml.


Is there anything in the ANT Build script where we can make a change to the file by searching a particular string .Such as making an entry in the Server.xml file.

Thanks in Advance
Posts: 67279
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To invoke a servlet, there must be a mapping for it.

In production systems, this is often simplified by use of the Front Controller pattern.

If you search around long enough, you might find mention of "the Invoker". Don't go there. It's a discredited technology.
Posts: 20995
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should NOT be deploying webapps by modifying server.xml. That's been discouraged since Tomcat 4 came out. Despite what the Tomcat plugin for Eclipse WST does. Tomcat 3 should be beyond dead by now.

When you deploy a webapp, you have to set up a context. The context defines the root URL for the webapp. You can deploy in several ways.

1. Copy a WAR file into TOMCAT_HOME/webapps. If you do this, the context name will be the same as the WAR file name (minus the ".war").

2. Copy an exploded (unzipped) WAR into a directory in TOMCAT_HOME/webapps. The context name will be the same name as the directory name. Copying straight into the root or TOMCAT_HOME/webapps doesn't deploy to "/", however, so you do need a directory.

3. (recommended) Create a Tomcat Context as an xml file. Store this file into TOMCAT_HOME/conf/Catalina/localhost/. This allows you to specify custom parameters such as a security realm, database connection pools and server-specific settings. Although you can also save this file as META-INF/context.xml within a WAR, this way makes it easier to customize the configuration without rebuilding the WAR. If you have both META-INF/context.xml and this context file, this one will override the one in the WAR.

4. (not recommended) Add context to server.xml. I already commented on this.

When you update a deployed WAR, exploded WAR or context xml file, Tomcat will detect the changes and redeploy the webapp after a short delay. That's another reason for not defining deployments in server.xml - it can't be dynamically updated.

Dynamic redeployment doesn't always work as hoped. Complex apps may need to be stopped and restarted in order to ensure that various bits and pieces get cleanly reset.
Paper beats rock. Scissors beats tiny ad.
professionally read, modify and write PDF files from Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!