2

I am looking for a way to programmatically set Java Options for Tomcat 6.0 running as a Windows service. When using startup.bat and shutdown.bat, you can set these variables in a setenv.bat or catalina.bat file. However, for Tomcat running as a Windows Service, these options must be manually set in the Java Options section of the configuration utility.

Is there any way to programmatically set these options?

Background: I am trying to write an installer that will deploy my app to an existing Tomcat 6.0 server. I can do everything else programmatically, but I'll still have to ask the user to manually add a few Java Options in these settings. This is less than ideal, especially since these options are case- and whitespace-sensitive.

Kip
  • 107,154
  • 87
  • 232
  • 265
  • The service configuration eventually goes into the Windows Registry. I'm not on Windows right now so I can't give you a proper answer, but it should be possible to manipulate registry keys in one way or another. – Mirko N. Jan 15 '10 at 20:51

1 Answers1

4

The Tomcat6 binary for running Tomcat as a Windows service has a bunch of command-line parameters that will likely help you. The only issue I foresee is that it's hard (impossible?) to retrieve the current settings so that you can modify them...

delfuego
  • 14,085
  • 4
  • 39
  • 39
  • 1
    thanks, this is working: `tomcat6 //US//Tomcat6 --JvmOptions="-DSetting1=Value1;-DSetting2=Value2"` However, as you said, this is a problem because it overwrites all of the existing java options, and I don't want to overwrite the settings for other apps that may be on this server – Kip Jan 15 '10 at 21:58
  • I was thinking about this on my drive home; I bet you can find the original settings in the Windows registry, and then modify them (maybe even in the registry directly, but definitely using the `tomcat6 //US//` command line method as well). SO had a thread about reading the registry in Java: http://stackoverflow.com/questions/62289/read-write-to-windows-registry-using-java ; I think that the Tomcat service info should live at HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Procrun 2.0\Tomcat6\. Totally kludgy, but I don't know if there's another way. – delfuego Jan 16 '10 at 00:58
  • The overwriting problem can be overcome by using 'tomcat6 //US//Tomcat6 ++JvmOptions="MyOption"' rather than the 'tomcat6 //US//Tomcat6 --JvmOptions="MyOption"' – Klee Jul 04 '11 at 05:26