4

I have an application installed in Tomcat that is invoked by the wrapper which sets an environment variable

set FOO=c:\foo

and invokes the startup.bat, and I have a requirement to run Tomcat as windows service.

So far, I tried to set the system environment variable, which did not help. I tried following the windows service HOWTO appending ++Environment in the registry, so that

 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tomcat7\Parameters\ImagePath 

looks like this

C:\Apache\Tomcat-7.0.64\bin\Tomcat7.exe //RS//Tomcat7 ++Environment=FOO=c:\foo

That did not help either.

Any suggestions, please

Shawn Mehan
  • 4,513
  • 9
  • 31
  • 51
PassoGiau
  • 587
  • 2
  • 7
  • 18
  • http://stackoverflow.com/a/6225751/3166303 – leeor Sep 24 '15 at 21:30
  • This link suggest tomcat tomcat5w.exe (and newer tomcat7w.exe etc). There is a way to pass java arguments, seems that is OK in this question. (answer say wrong, this tab isnt visible from widows service scree) Windows service are at general hard to pass command-line arguments. Existing field on first tab works only by manual Start – Jacek Cz Sep 25 '15 at 10:41
  • No, this is not an argument, nor it is a system property. It's an environment variable. – PassoGiau Sep 25 '15 at 18:04

3 Answers3

4

You were almost there. Replace the equal sign with a space in your tomcat7 command, and that should work.

I've just written this up on another question: Setting User Environment Variables for tomcat on Windows

Community
  • 1
  • 1
hktegner
  • 558
  • 4
  • 9
2

I had to change --JvmOptions of the service.bat file then remove the service and re-install again.

--JvmOptions "-Dspring.profiles.active=pp;-Dcatalina.home=%CATALINA_HOME%;...."
Mr_Pouet
  • 4,061
  • 8
  • 36
  • 47
Subhas
  • 46
  • 3
0

I have a InstallService.bat file. In the file I am first creating the service without specifying the Environment variable and then I am updating the service with the Environment variable specified.This is how the bat file looks like.

tomcat8 //IS//CompassTomcat8_8080 --DisplayName="Compass Apache Tomcat 8:8080" --Install=%CATALINA_HOME%\bin\tomcat8.exe --Startup=auto
tomcat8 //US//CompassTomcat8_8080 --DisplayName="Compass Apache Tomcat 8:8080" --Install=%CATALINA_HOME%\bin\tomcat8.exe --Startup=auto --Environment=Key1=Value1;Key2=Value2

It has started working now.

Deepak Pandey
  • 618
  • 7
  • 19