Search code examples
websphereweb.xmlcontext-param

How to define context parameters in the WebSphere config, instead of the web.xml?


With Tomcat, with a <Parameter> placed inside a <Context> (e.g. in Tomcat's server.xml), it is possible to define context parameters for a web app outside of the web app itself, i.e. without having to change the web.xml.

This is convenient in cases where the same war is being deployed on multiple servers, and you'd like to configure the web app in each case, but this without having to modify the content of the war.

For more on this feature in the context of Tomcat, see the Tomcat doc on context parameters. Does WebSphere provide a similar capability?


Solution

  • The conventional way to define environment-specific information for Java EE web module is to use <env-entry> in web.xml, for example:

    <env-entry>
        <env-entry-name>entryName</env-entry-name>
        <env-entry-type>java.lang.Integer</env-entry-type>
        <env-entry-value>1</env-entry-value>
    </env-entry>
    

    Then the value of an entry can be obtained through JNDI in java:comp/env namespace.

    The value can be specified during deployment via WAS-specific deployment descriptor or changed later in WAS console (Enterprise Applications / your_app / Web Module Properties / Environment entries for Web modules)