Bug 48394 - Support for "path" attribute in context.xml
Summary: Support for "path" attribute in context.xml
Status: RESOLVED WONTFIX
Alias: None
Product: Tomcat 6
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 6.0.20
Hardware: PC Windows NT
: P2 enhancement (vote)
Target Milestone: default
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-15 15:37 UTC by Mike Youngstrom
Modified: 2009-12-15 16:25 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Youngstrom 2009-12-15 15:37:11 UTC
Currently Tomcat provides basically 2 ways to set the context path of an application.

* Derived from the name of the .war or {context}.xml file.
* Set the path attribute of the context element in the server.xml

It would be nice if it were possible to set the path attribute in the context element of a context.xml file.

I have a requirement where my application's context path must change depending upon the environment it is deployed into.  Instead of renaming my .war for each environment I would prefer to set the path attribute in the context.xml of the .war to a catalina.properties property.  (e.g. <context path="${contextPath}"/>)

Then set the value of ${contextPath} in my catalina.properties for the different environments along with the other properties in my application that change for each environment such as database connection information.

I could add a context entry in my server.xml but I'm hoping to keep application specific configuration information out of my server.xml.  And from my understanding use of context element in server.xml is somewhat deprecated.

If the path attribute is empty the tomcat can derive the context Path from the file name just like it does now by default.  I just want to add support for the path attribute if it is specified.

I'd be more than willing at taking a stab at a patch if I could get some sort of assurance that the general concept of this issue is valid.
Comment 1 Mark Thomas 2009-12-15 16:25:45 UTC
Such a change is likely to result in unwanted double deployment for many users as well as significantly complicating the auto (un)deployment logic.

Defining contexts in server.xml is not deprecated. It is discouraged for those use cases where the context could be defined outside server.xml

One possible solution would be to place your war files outside of the host's appBase and use context.xml files in CATALINA_BASE/conf/Catalina/localhost. The path will be derived from the name of the xml file but the WAR file can be named whatever you like.

Another solution is to disable autoDeploy and deployOnStartup for the host and explicitly define the contexts in server.xml

If you need further advice on your options in this area, please ask on the users list.