Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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...)

share|improve this question

5 Answers 5

up vote 2 down vote accepted

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.

share|improve this answer

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

Cheers

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

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.

share|improve this answer
    
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 '09 at 5:36

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
share|improve this answer
    
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 '09 at 18:35
    
Can't you just put it in the environment of the user running the Tomcat or in a wrapper .bat file? –  Aaron Brown Oct 30 '09 at 18:12

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.

HTH, jnoob22

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.