0

I am trying to set a system property in tomcat config file so it can be read by System.getProperty() code. This is probably a simple task but I am not able to figure this out. Here is want I tried with no success.

Modified context.xml in tomcat settings.

<Context>
      ....
     <Parameter name="run.mode" value="test"/>
     <Environment name="run.mode" value="test" type="java.lang.String"/>
</Context>

I don't want to modify container settings, just the server settings.

PS. I am fairly new to to the container and JVM webapp world. Still making sence of things. Right now I am working with Lift.

Mike Starov
  • 7,000
  • 7
  • 36
  • 37

1 Answers1

2

Use the JAVA_OPTS environment variable when launching Tomcat, like this:

JAVA_OPTS='-Drun.mode=test' start.sh
erickson
  • 265,237
  • 58
  • 395
  • 493
  • I am using a packaged tomcat. So I start is using `service tomcat5 start`. There is probably a way to get that -D flag in there somewhere but is this really the way you do it? – Mike Starov Nov 12 '10 at 22:41
  • This worked. I added `JAVA_OPTS="-Drun.mode=test"` to /etc/tomcat5/tomcat5.conf. This is running on CentOS 5.5 – Mike Starov Nov 12 '10 at 22:45
  • Better to use `CATALINA_OPTS` instead of `JAVA_OPTS`: `JAVA_OPTS` will set the options for all invocations of the JVM, including shutdown, etc. `CATALINA_OPTS` will only be used when launching Tomcat. – Christopher Schultz Jul 13 '12 at 01:19
  • @ChristopherSchultz No, specifying any environment variable as I have shown will affect only that invocation of the command. Mike's solution works that way as well. – erickson Jul 13 '12 at 04:08
  • You're right @erickson, I was thinking of setting the variable for the shell in general and not just a single command. I was mostly trying to illustrate the difference between `JAVA_OPTS` and `CATALINA_OPTS`. – Christopher Schultz Jul 13 '12 at 12:32