Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable JMXMP in Tomcat?

I've downloaded the JMXMP extensions and installed them in Tomcat's lib directory. Now, how can I make it use them, i.e. let Tomcat accept JMXMP connections?

  • Oracle's examples show how to do it with code, for which I'd have to write my own listener, which I'd rather keep as a last resort.
  • Tomcat's JMX listener does not seem to include JMXMP support.
like image 697
Bart van Heukelom Avatar asked Jul 10 '12 12:07

Bart van Heukelom


2 Answers

Well, I wrote my own JMXMP Tomcat 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 a day of breaking my head on this issue, I'm now able to use VisualVM on my application.

like image 178
Bart van Heukelom Avatar answered Nov 19 '22 05:11

Bart van Heukelom


I created a mvn project based on Bart von Heukeloms' answer with the needed tomcat-catalina as provided dependency: jmxmp-lifecycle-listener

Just to be plugged in to tomcat's server.xml:
<Listener className="javax.management.remote.extension.JMXMPLifecycleListener" port="5555" />

I don't have enough reputation, otherwise I would have posted this as a comment.

like image 3
Felix Oldenburg Avatar answered Nov 19 '22 06:11

Felix Oldenburg