TomEE makes JMXMP usage simple

Tomcat includes out of a box a Listener to simplify JMX usage but it mainly handles default connector – JVM one).

Often in enterprise you need to use another one. The most known is JMXMP.

To make it easy to use in TomEE, you can now use JMXServerListener.

Just add in your server.xml this new listener:

<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.tomee.catalina.ServerListener" />

  <!-- this listener will handle jmxmp server lifecycle -->
  <Listener className="org.apache.tomee.loader.listener.JMXServerListener"
            port="1234" />

  <Service name="Catalina">
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000" />

    <Engine name="Catalina" defaultHost="localhost">
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true" />

You can of course configure the host, port, potentially urlPath and the protocol. Note if you don’t provide the protocol jmxmp will be used.

Now to make it working you need to add jmxmp to the container. It is provided as a jar (you can find several ones on the internet). I used org.glassfish.external:opendmk_jmxremote_optional_jar:1.0-b01-ea. To make it easier I added it using TomEE container provisioning feature.

Just create a file conf/ with the line:

jar = mvn:org.glassfish.external:opendmk_jmxremote_optional_jar:1.0-b01-ea

Now you can start TomEE :).

When it starts it logs somethings like:

Infos: Started JMX server: service:jmx:jmxmp://localhost:1234

JMXMP is not in the JVM (that’s why we added a jar to TomEE) so to connect with a client (JConsole, JVisualVM, JMC…) you need to add this jar as well.

Here is a sample for JConsole:

java -cp $JAVA_HOME/lib/jconsole.jar:$CATALINA_HOME/additionallib/opendmk_jmxremote_optional_jar-1.0-b01-ea.jar service:jmx:jmxmp://localhost:1234

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s