How to enable JMXMP in Tomcat?

I downloaded the JMXMP extensions and installed them in the Tomcat lib directory. Now, how can I get them to use them, i.e. Allow Tomcat to accept JMXMP connections?

  • The Oracle examples show how to do this with code for which I would have to write my own listener, which I would rather keep as a last resort.
  • The Tomcat JMX listener does not seem to support JMXMP support.
+5
source share
2 answers

I created the mvn project based on the answer of Bart von Heukeloms with the necessary braid-catalina, depending on the installed dependency: jmxmp-lifecycle-listener

Just to connect to tomcat server.xml:
  <Listener className="javax.management.remote.extension.JMXMPLifecycleListener" port="5555" />

I don't have enough reputation, otherwise I would post it as a comment.

+3
source

Well, I wrote my own Tomcat JMXMP listener. Feel free to use:

package webersg.tomcat;

import java.lang.management.ManagementFactory;

import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;

import org.apache.catalina.Lifecycle;
import org.apache.catalina.LifecycleEvent;
import org.apache.catalina.LifecycleListener;

public class JMXMPLifecycleListener implements LifecycleListener {

    private int port = 5555;

    private JMXConnectorServer cs;

    @Override
    public void lifecycleEvent(LifecycleEvent event) {

        try {

            // START
            if (Lifecycle.START_EVENT == event.getType()) {

                System.out.println("Start JMXMP on port " + port);

                cs = JMXConnectorServerFactory.newJMXConnectorServer(
                        new JMXServiceURL("jmxmp", "0.0.0.0", port),
                        null,
                        ManagementFactory.getPlatformMBeanServer()
                );
                cs.start();

                System.out.println("Started JMXMP");

            }

            // STOP
            else if (Lifecycle.STOP_EVENT == event.getType()) {

                System.out.println("Stop JMXMP");

                cs.stop();
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}

So, after I ran into this problem, I can now use VisualVM in my application.

+2
source

All Articles