How to enable JMXMP in Tomcat?

旧街凉风 提交于 2019-11-29 21:42:41

问题


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.

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/11413178/how-to-enable-jmxmp-in-tomcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!