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.
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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.