The Source for Java Technology Collaboration
User: Password:



Amy Roh

Amy Roh's Blog

Context (webapp) configuration in GlassFish

Posted by amyroh on May 23, 2007 at 01:33 PM | Comments (6)

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

Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • Beauty wit Brain

    Posted by: javaniraj on May 24, 2007 at 09:03 AM

  • Would that work also using a "deployed" application or does that just work with war files?

    I have not tried GF yet, but we don't use war files so that would be nice to have also.

    S!

    Posted by: greeneyed on May 24, 2007 at 09:52 AM

  • You can put context.xml in your deployed webapp (META-INF/context.xml). You'll need to restart GlassFish for changes to take effect.

    Thanks,
    Amy

    Posted by: amyroh on May 24, 2007 at 10:35 AM

  • Good to know, thanks!
    S!

    Posted by: greeneyed on May 24, 2007 at 11:16 AM

  • Fair enough, but how do I use it in my Java code??? I thought this goes into java/env but it doesn't work for me :-(

    Posted by: sshahar1 on April 08, 2008 at 03:47 AM

  • I meant java:comp/env

    Posted by: sshahar1 on April 08, 2008 at 04:00 AM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds