Deployment specific web application configuration usingcontext.xml in GlassFish was addeda couple of months ago but related questions keep coming up on mailing lists and forumso I've decided to blog about it so it's easy to point out. ;-)

Similar to Tomcatyou can define your context.xml as follows.

1. Global context.xmlglassfish/domains/domain1/config/context.xml which will be loaded by *all* webapps.

For example, global context.xml can define global environment entry to be shared across all webapps as follows.

<Environment name="global_environment" type="java.lang.String" value="global_environment_value"/>

2. Virtual server context.xml specified by virtual-server property "contextXmlDefault" in domain.xmlwill be loaded by all webapps of this virtual server.

For examples, you can define contextXmlDefault for a virtual server in your domain.xml as follows.

<virtual-server id="server" ... >
<property name="contextXmlDefault" value="config/context.xml.default"/>

3. Webapp specific context.xml will be loaded by this webapp only.

You can define /META-INF/context.xml in a WAR file for this webapp specific environment and resource definitions.

<Environment name="webapp-env" type="java.lang.String" value="webapp-env-value"/>
<Resource name="jdbc/__default" auth="Container" type="javax.sql.DataSource" description="Default Database"/>

GlassFish V2 Beta 2 or later should have this feature.