You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jason Pringle <Ja...@amdocs.com> on 2011/07/30 01:04:41 UTC

Getting an absolute path into a servlet's context-param value w/o hardcoding in web.xml

Hi all,

We have a 3rd party application that is deployed into our environment.  As it is 3rd party we have no control over changing the servlet code itself.

As part of the "configuration" of the servlet to be deployed into an environment, it wants a directory path passed as a servlet context parameter:

(WEB-INF/web.xml)
....
  <context-param>
    <param-name>3rd-party-app.home</param-name>
    <param-value>/path/to/directory</param-value>
  </context-param>
....

In our environments, "/path/to/directory" will be different for different deployments, and so we don't want to hardcode this into the web.xml else the WAR is non-portable.

A very annoying work around we came up with is to specify a relative path, but this has the nasty effect of forcing the container to be started from a specific directory (ops guys don't like that!):

(WEB-INF/web.xml)
  <context-param>
    <param-name>3rd-party-app.home</param-name>
    <param-value>../../relative/path/to/directory</param-value>
  </context-param>

I'm sure there's a better way to do this, but am still scratching my head.

Does tomcat still dereference the system properties when parsing a WAR's web.xml?  Would something like this work?

(catalina.properties)
foo.home=/path/to/directory

(WEB-INF/web.xml)
  <context-param>
    <param-name>3rd-party-app.home</param-name>
    <param-value>${foo.home}</param-value>
  </context-param>


I've also thought about a custom listener or similar that would load before the context-params are read and set the context-param value by reading a system property set via catalina.properties.

Thanks!

--Jason Pringle

This message and the information contained herein is proprietary and confidential and subject to the Amdocs policy statement,
you may review at http://www.amdocs.com/email_disclaimer.asp


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Getting an absolute path into a servlet's context-param value w/o hardcoding in web.xml

Posted by chris derham <ch...@derham.me.uk>.
>
> As part of the "configuration" of the servlet to be deployed into an
> environment, it wants a directory path passed as a servlet context
> parameter:
>
> (WEB-INF/web.xml)
> ....
>  <context-param>
>    <param-name>3rd-party-app.home</param-name>
>    <param-value>/path/to/directory</param-value>
>  </context-param>
> ....
>
> In our environments, "/path/to/directory" will be different for different
> deployments, and so we don't want to hardcode this into the web.xml else the
> WAR is non-portable.
>
> Put the following on <tomcat_home>/conf/context.xml and it will override
the value in web.xml - override false means should web.xml override this
value, so it has to be false

    <Parameter name="3rd-party-app.home" value="/path/to/other/directory"
override="false"/>

This will set this parameter for all wars in the tomcat instance.
Alternatively you can specify the setting in a per war file via placing it
in <tomcat_home>conf/Catalina/localhost/AppName.xml

Hope that helps

Chris