Windows – How to enable JMX on tomcat7 running as Windows service

tomcatwindows

I have googled this extensively before posting it here. I've been trying to find out a way to enable JMX Access on a Tomcat instance installed as Windows service. Its quite straightforward when Tomcat is invoked via the startup.bat script, one just needs to set the CATALINA_OPTS environment variable to something like "-Dcom.sun.management.jmxremote.port=1234 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"

But how do i get the Tomcat Windows service to read these options? I tried this:

C:>tomcat\server\bin> service.bat install #install the Tomcat7 windows service

C:>tomcat\server\bin> tomcat7.exe //US//Tomcat7 ++JvmOptions "-Djava.io.tmpdir=$INSTDIR\server\temp;-XX:MaxPermSize
=256m;-Dcom.sun.management.jmxremote.port=8090;-Dcom.sun.management.jmxremote.au
thenticate=false;-Dcom.sun.management.jmxremote.ssl=false" –JvmMs 256 –JvmMx 1
024
#update the installed service using the //US switch; set tmpdir, JMX access and heap size

When i start the service from Services panel, the service fails to start and i get the following error on the logs\tomcat7-stderr-yyyy-mm-dd.log file:

yyyy-mm-dd hh:mm:ss Commons Daemon procrun stderr initialized
Error: Invalid com.sun.management.jmxremote.port number: 8090 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false

I don't have a Java background, am i trying to achieve something outlandish here? Please advise.

Best Answer

Answering my own question; turned out to be easier than i thought.

Following needs to be done, for enabling JMX access for Tomcat installed as a Windows service, that has a name "ApacheTomcatWindowsServer" for example:

  • Install Tomcat as Windows service, either using the command (first cd into \bin\ )

service.bat install

or your custom scripts.

  • Enable Apache Service Manager for the installed service using the following command:

tomcat7w.exe //MS//ApacheTomcatWindowsServer

This should start Apache Service Monitor program on your system tray. Click on its icon. select 'Configure', click on the 'Java' tab and append the following on the 'Java Options' text box, one option per line:

-Dcom.sun.management.jmxremote.port=8090

-Dcom.sun.management.jmxremote.authenticate=false

-Dcom.sun.management.jmxremote.ssl=false

Save and exit and restart the service.

  • To connect to the JMX console, fire jconsole from your JDK installation, click 'New Connection', specify 'Remote Process' and enter hostname:8090.