10

I'm trying to configure Java options passed into TomCat for a 3rd party application that I'm deploying. The instructions that the app provides are:

  1. Open the Tomcat configuration tool from the Windows menu at Start > All Programs > Apache Tomcat > Tomcat Configuration.
  2. Click Configure and select the Java tab.
  3. At the bottom of the Java Options field, enter the following:
    -Dexample.license.directory="C:\Program Files\example"
  4. Stop and restart the application server.

However, I need to do this programmatically, so I'd like to know what config file these options can be set in. Using the GUI is impractical for deploying the app to other developers' environments.

(I'm using Tomcat 6.0 if that is relevant...)

5 Answers 5

6

If you're using Tomcat as a Windows service, you can adjust the JVM options by going to the bin dir and running:

tomcat6 //US//MYSERVICENAME ++JvmOptions=-Dexample.license.directory="C:\Program Files\example"

Turn the service off before you do this and restart it when you finish.

I just did this for my own tomcat server and it handled it for me.

1

The best way is to use setenv.sh/setenv.bat. It isn't in the as-downloaded Tomcat. But if you look in catalina.sh/catalina.bat, there's a check for a file called setenv. If it's there, it's run. That's where you set JAVA_OPTS, CATALINA_OPTS, etc. We use it to set JAVA_HOME, JAVA_OPTS, CATALINA_OPTS and JPDA_ADDR.

For Tomcat6, this file can be deployed to your CATALINA_BASE directory where it will be run. For previous versions of Tomcat (5, 5.5 at least) it has to be in CATALINA_HOME.

Putting all your environment variables into this file is ideal because then you don't have to change the stock startup scripts.

1
  • 1
    this works if i use startup.bat. but if i run it as a windows service (using service.bat to install it), it doesn't seem to parse any of the bat files
    – Kip
    Nov 1, 2009 at 5:36
0

You should be able to set the environment variable JAVA_OPTS.

In Linux, it would look like this

 export JAVA_OPTS="$JAVA_OPTS -DclusterProperties=$MPFPROOT/ClusterProperties.properties -Xmx1024m -Xms1024m "

I'm not up on my Windows environment variables...I think you'd use

set JAVA_OPTS=somethingsomething
2
  • Not a great option for me. I want it to run as a Windows service, but I don't want to set a global JAVA_OPTS variable...
    – Kip
    Oct 29, 2009 at 18:35
  • Can't you just put it in the environment of the user running the Tomcat or in a wrapper .bat file? Oct 30, 2009 at 18:12
0

You can set JAVA_OPTS in $TOMCAT_HOME\bin\catalina.bat

Cheers

2
  • 2
    That works if I use startup.bat, but if I install as a service it doesn't seem to like it
    – Kip
    Oct 30, 2009 at 18:03
  • i can actually completely remove catalina.bat, and the apache service still starts OK
    – Kip
    Oct 30, 2009 at 18:07
0

If Tomcat is set as a service, you'll need to do something like:

In the command line go to tomcat\bin tomcat6w.exe //ES //MYSERVICE

This will open a gui dialog box where you can make the settings.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .