This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Tomcat and the fly likes To Author: Configuring context at web application level Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "To Author: Configuring context at web application level" Watch "To Author: Configuring context at web application level" New topic
Author

To Author: Configuring context at web application level

Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Hi Matthew,

Welcome to JavaRanch.

Could you please give a quick overview of configuring the context at web application level, with the purpose of reducing the steps needed to deploy a webapp on tomcat.

An approach favoured by many developers is to keep all JSPs under WEB-INF directory to provide access to those only through controller servlets. Is that possible with Tomcat? In your experience, do most other application servers allow this as well?

Thanks
Sonny


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
Matthew Moodie
author
Greenhorn

Joined: Oct 18, 2002
Posts: 14
Hi,

Could you please give a quick overview of configuring the context at web application level, with the purpose of reducing the steps needed to deploy a webapp on tomcat.


Tomcat 5 uses a context XML file that contains context configuration information. At the web application level, this file is named after the web appliaction, so for a webapp named myWebApp the file will be called myWebApp.xml, and is placed in CATALINA_HOME/conf/[engine_name]/[host_name].

Its root element is the <Context> element and you can use this to define context attributes such as the webapp's document base, the context's path and Tomcat's working directory for this webapp.

With this in mind, you can see that you can have the web application code in any location on the server and point to it with the context XML file. This file can then be placed in CATALINA_HOME/conf/[engine_name]/[host_name] without moving any other files.

If the containing host's deployOnStartup flag is set to true, then the context is deployed on Tomcat startup. If Tomcat is already running and the containing host's autoDeploy flag is set to true (the default), then dropping the context XML file into CATALINA_HOME/conf/[engine_name]/[host_name] will deploy the application.

This means that you need to provide a single file for deployment, rather than altering other configuration files and copying web applications into Tomcat's directory hierarchy.

An approach favoured by many developers is to keep all JSPs under WEB-INF directory to provide access to those only through controller servlets. Is that possible with Tomcat? In your experience, do most other application servers allow this as well?


Yes, this is possible in Tomcat because it is the reference implementation of the Servlet 2.4 and JSP 2.0 specs, which allow this. If an application server is certified as complying with the specs, it will also allow this.

Matt
[ March 02, 2005: Message edited by: Matthew Moodie ]

Author of <a href="http://www.amazon.com/exec/obidos/ASIN/1590593316/ref=jranch-20" target="_blank" rel="nofollow">Pro Jakarta Tomcat 5</a>
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Thanks a lot, Matthew.

How about setting up the context in /META-INF/context.xml as described in

http://jakarta.apache.org/tomcat/tomcat-5.5-doc/appdev/deployment.html


A /META-INF/context.xml file can be used to define Tomcat specific configuration options, such as loggers, data sources, session manager configuration and more. This XML file must contain one Context element, which will be considered as if it was the child of the Host element corresponding to the Host to which the The Tomcat configuration documentation contains information on the Context element.


Can I copy the CATALINA_HOME/conf/[engine_name]/[host_name]/myWebApp.xml file, generated when deploying an application called myWebApp using the Tomcat Manager app, as META-INF/context.xml, and so have all the setup in my WAR file?
Matthew Moodie
author
Greenhorn

Joined: Oct 18, 2002
Posts: 14
Hi,

Can I copy the CATALINA_HOME/conf/[engine_name]/[host_name]/myWebApp.xml file, generated when deploying an application called myWebApp using the Tomcat Manager app, as META-INF/context.xml, and so have all the setup in my WAR file?


Yes, you can. Note that it will only be read if there is no corresponding myWebApp.xml file in CATALINA_HOME/conf/[engine_name]/[host_name]. In other words, the file outside the WAR takes precedence over the file in the WAR.

HTH,

Matt
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Thanks for your help, Matt. Cheers.
 
 
subject: To Author: Configuring context at web application level
 
Similar Threads
When calling https://www.myhost.com tomcat says 'The requested resource / is not available'.
How to assing IP address to web application?
problem in context root
JDBC Realm inside the COntext element
(ANOTHER) Question from Head First Servlets and JSP's