The Source for Java Technology Collaboration
User: Password:
Register | Login help    

Search

Online Books:
java.net on MarkMail:


Context (webapp) configuration in GlassFish

Posted by amyroh on May 23, 2007 at 1:33 PM PDT
Deployment specific web application configuration using context.xml in GlassFish was added a couple of months ago but related questions keep coming up on mailing lists and forum so I've decided to blog about it so it's easy to point out. ;-)

Similar to Tomcat you can define your context.xml as follows.

1. Global context.xml glassfish/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.

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


2. Virtual server context.xml specified by virtual-server property "contextXmlDefault" in domain.xml will 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"/>
</virtual-server>


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.

<Context>
<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"/>
</Context>


GlassFish V2 Beta 2 or later should have this feature.

Cheers,
Amy
Related Topics >> Java Enterprise      
Comments
Comments are listed in date ascending order (oldest first)