How to use Tomcat Context information in GlassFish


If you’re using Tomcat and you are looking into moving to GlassFish (because of Java EE 5, admin tools, Grizzly performance, etc…), you might find this question I was asked twice recently about a specific feature migration.

If you were using Tomcat’s Context feature and reading the initialization parameters say from servletContext.getInitParameter(), you need to provide the same information in a slightly different format in the standard web.xml deployment descriptor.


<context-param>
   <param-name>param</param-name>
   <param-value>value</param-value>
</context-param>

Note this can also be added to $GLASSFISH_HOME/domains/$DOMAIN_NAME/config/default-web.xml if you don’t want to repeat this in all your web-apps. But be careful as it takes precedence over the web application web.xml.

Author: alexismp

Google Developer Relations in Paris.

2 thoughts on “How to use Tomcat Context information in GlassFish”

  1. Hi,
    Great feature !
    But is-it possible to use it “à la” Tomcat ?
    Sample :
    You have a webapp called sample and you want to set a special context file only for this webapp (as I understand the current
    feature will shared values for all webapp ?).
    With tomcat put a context file in $CATALINA_HOME/conf/Catalina/localhost/sample.xml
    And the sample.xml context values will not be shared for all other webapps.
    An other point : is it deployable on life ?
    With a cli or an ant task, something like deploy -f warPath -contextPath contextPath


    Olivier

  2. No, this is not a global setting if you use web.xml (per web-app setting).

    I’m not sure I understand the second part of the question, but I guess this should help:

    CLI: % bin/asadmin deploy –contextroot mywebapp.war

    ANT: you’re probably looking for the sun-appserv-deploy ant task.

Comments are closed.