#StackBounty: #java #jmx #tomcat8 Why can't I get JMX to run with Tomcat8 through CATALINA_OPTS?

Bounty: 50

According to https://tomcat.apache.org/tomcat-8.0-doc/monitoring.html#Introduction I should be able to active JMX by setting some env variables on CATALINA_OPTS. I’ve done this:

export CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"

Some places seem to suggest I need catalina-jmx-remote.jar in $CATALINA_OPTS/lib which I have:

$ ls -l /opt/tomcat/apache-tomcat-8.0.37/lib/catalina-jmx-remote.jar
-rw-r--r-- 1 root root 13608 Jan 18 23:05 /opt/tomcat/apache-tomcat-8.0.37/lib/catalina-jmx-remote.jar

I’ve also made sure the environment variable is properly set:

$ sudo cat /proc/20893/environ
LANG=en_USLANGUAGE=en_US:PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binHOME=/srv/tomcatLOGNAME=tomcatUSER=tomcatSHELL=TOMCAT_JAVA_HOME=/opt/java/oracle/jdk1.8.0_112CATALINA_HOME=/opt/tomcat/apache-tomcat-8.0.37CATALINA_BASE=/srv/tomcat/catalina/tomcatCATALINA_OPTS=-Djava.rmi.server.hostname=172.16.29.134 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false

Despite this, JMX is not listening on 1099 and I cannot connect to it:

$ netstat --listen | grep 1099

If I run a regular java program with:

$ java -Djava.rmi.server.hostname=172.16.29.134 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false HelloWorld

This also seems to work if I pass it as args when starting tomcat:

/opt/java/oracle/jdk1.8.0_112/bin/java 
  -Djava.util.logging.config.file=/srv/tomcat/catalina/%i/conf/logging.properties 
  -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 
  -Djava.security.egd=file:/dev/./urandom 
  -Djava.endorsed.dirs=/opt/tomcat/apache-tomcat-8.0.37/endorsed 
  -Dcatalina.home=/opt/tomcat/apache-tomcat-8.0.37 
  -Dcatalina.base=/srv/tomcat/catalina/%i 
  -Djava.io.tmpdir=/srv/tomcat/catalina/%i/temp 
  -Djava.net.preferIPv4Stack=true 
  -Djava.rmi.server.hostname=172.16.29.134 
  -Dcom.sun.management.jmxremote.authenticate=false 
  -Dcom.sun.management.jmxremote.port=1099 
  -Dcom.sun.management.jmxremote.ssl=false 
  -classpath "/opt/tomcat/apache-tomcat-8.0.37/bin/bootstrap.jar:/opt/tomcat/apache-tomcat-8.0.37/bin/tomcat-juli.jar" 
  org.apache.catalina.startup.Bootstrap start

So why doesn’t CATALINA_OPTS get picked up like the documentation suggests? What is it I’m missing?


Get this bounty!!!