17
votes

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.

2
Never tried it, but have you checked this: tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.htmlDarius X.
Yes, i did refer to this page. It says that the parameter ++JvmOptions accepts list of options starting with -D or -X. So while it does accept -Djava.io.tmpdir and -XX:MaxPermSize options; -Dcom.xxx options aren't supported it seems.user1175135
The message has the word "number". So it does seem like it "knows" you're trying to pass a port#, but it does not like the value.Darius X.
Sorry for late reply. As for the number part, the Apache documentation here says that the the following parameters need to be set CATALINA_OPTS=-Dcom.sun.management.jmxremote \ -Dcom.sun.management.jmxremote.port=%my.jmx.port% \ -Dcom.sun.management.jmxremote.ssl=false \ -Dcom.sun.management.jmxremote.authenticate=false So the jmxremote.port parameter is the same as i tried defining. As for the port number, i think its a TCP port so i ensured that it isn't already in use.user1175135

2 Answers

27
votes

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.
3
votes

you can also uninstall the service by

service.bat remove

then edit the service.bat and add the parameters in your StartPath and add the options

-Djavax.management.builder.initial=;-Dcom.sun.management.jmxremote.port=8090;-Dcom.sun.management.jmxremote.authenticate=false;-Dcom.sun.management.jmxremote.ssl=false

here is the sample StartPath in my file

--StartPath "C:\tomcat7\" --Startup auto --JvmOptions "-Dcatalina.home=%CATALINA_HOME%;-Dcatalina.base=%CATALINA_BASE%;-Djava.endorsed.dirs=%CATALINA_HOME%\endorsed;-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties;-Djava.rmi.server.hostname=;-Djavax.management.builder.initial=;-Dcom.sun.management.jmxremote.port=8090;-Dcom.sun.management.jmxremote.authenticate=false;-Dcom.sun.management.jmxremote.ssl=false" %JAVA_OPTS% ^

re-install the service by

service.bat install

then start Tomcat to apply changes