user1197126
user1197126

Reputation: 61

Setting java_opts to tomcat service from command line

I have a tomcat7 service running on windows, Usually in order to configure the Java options I go to Tomcat 7.0\bin\tomcat7w.exe and there in java tab, in java options I print the definition I want, for example -javaagent:... I want to do this through command line or using some script to have it automated, is there any way to achieve this and still run the tomcat as a service? (right now I run tomcat through cmd: "sc tomcat7 start").

Thanks

Upvotes: 3

Views: 5311

Answers (1)

David Conneely
David Conneely

Reputation: 936

See http://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html#Updating_services

You can run something like the following (the first "tomcat7.exe" is the service executable name, and the second "//US//tomcat7" is the service name prefixed with //US//, meaning "update service"):

tomcat7.exe //US//tomcat7 "--JvmOptions=-Xrs;-javaagent:xyz"

The values passed with the --JvmOptions flag are semicolon separated JAVA_OPTS flags. If you do this while the service is not running, i.e. before you execute:

sc.exe tomcat7 start

then it will affect subsequent starts of that "tomcat7" Tomcat service.

Upvotes: 4

Related Questions