- -Dcom.sun.management.jmxremote.port=9999
- -Dcom.sun.management.jmxremote.ssl=false
- -Dcom.sun.management.jmxremote.authenticate=false
This will start the tomcat server on port 9999. Use these JVM options in the catalina.bat file - and keep them as JAVA_OPTS.
Once tomcat has opened this port, connect to tomcat using this sample code -
- JMXServiceURL jurl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi");
- JMXConnector jmxc = JMXConnectorFactory.connect(jurl, null);
- MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
This will connect to the tomcat server running on localhost with port 9999.
To fetch the value of an attribute - use the following code -
-
mbsc.getAttribute(
new ObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME, "VmVersion");
The above code will fetch the JVM version of the tomcat JVM using the standard runtime MBean of the JVM.