Context (webapp) configuration in GlassFish
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><br>
<Environment name="global_environment" type="java.lang.String" value="global_environment_value"/><br>
</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" ... ><br>
<property name="<strong>contextXmlDefault</strong>"
value="config/context.xml.default"/><br>
</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><br>
<Environment name="webapp-env" type="java.lang.String" value="webapp-env-value"/><br>
<Resource name="jdbc/__default" auth="Container"
type="javax.sql.DataSource"
description="Default Database"/><br>
</Context>GlassFish V2 Beta 2 or later should have this feature.
Cheers,
Amy
- Login or register to post comments
- Printer-friendly version
- amyroh's blog
- 5627 reads






Comments
<p>This is a great post; it was very informative. I look ...
by sozi - 2011-07-15 08:23
This is a great post; it was very informative. I look forward in reading more of your work. Also, I made sure to bookmark your website so I can come back later. I enjoyed every moment of reading it. internet marketing
testking
Why using a context.xml resource like in Tomcat ?
by cistox - 2010-06-16 23:10
This is actually an issue as the context.xml is not a standard J2EE resource but proprietary... so now it is overlapping the context of tomcat, which means I cannot have the same web application deployed on glassfish and tomcat using Netbeans. I am constrained to duplicate the project just to have two different context.xml as they are not compliant at all (see realm settings) Why not sun-context.xml ? All sun specific server resources have been always starting with sun-... Overlapping is not a good thing. Roberto