0
votes

I use eclipse + tomcat + maven.

When I deploy my project to Tomcat, the following entry gets added to the server.xml of the tomcat configuration:

<Context docBase="C:\ws_eclipse\ws\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\MyApp" path="/myApp" reloadable="true" source="org.eclipse.jst.jee.server:MyApp"/>

What I actually want is to add an environment variable so that the context looks like this:

  <Context docBase="C:\ws_eclipse\ws\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\MyApp" path="/myApp" reloadable="true" source="org.eclipse.jst.jee.server:MyApp">
       <Environment name="config.file" type="java.lang.String" value="C:/test/config.xml" /> 
</Context>

I tried adding it as an environment variable in eclipse run configuration, but when I deployed the application on tomcat, the context does not include the environment variable.

2

2 Answers

3
votes

You could add a context.xml file in the META-INF directory of your webapp. The content of this file may look like:

<Context>
  <Parameter name="config.file" value="C:/test/config.xml"/>
</Context>

This has the same effect as defining a <context-param/> in your web.xml. Use ServletContext.getInitParameter("config.file") to retrieve it's value as a String.

You may use Environment as well, but it's probably overkill (You just need a String anyway, I think).

See http://tomcat.apache.org/tomcat-6.0-doc/config/context.html

1
votes

Setting it in application launch configuration is the best way, you might want to verify what you did at here - Creating a Java application launch configuration

HTH