I've downloaded the JMXMP extensions并将它们安装在Tomcat的lib目录中。现在,我如何让它使用它们,即让Tomcat接受JMXMP连接?
答案 0 :(得分:3)
好吧,我编写了自己的JMXMP Tomcat监听器。随意使用:
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);
}
}
}
因此,在这个问题上突破了一天之后,我现在能够在我的应用程序上使用VisualVM。
答案 1 :(得分:3)
我创建了一个基于Bart von Heukeloms' answer的mvn项目,其中包含所需的tomcat-catalina依赖项:jmxmp-lifecycle-listener
只需要插入tomcat的server.xml:
<Listener className="javax.management.remote.extension.JMXMPLifecycleListener" port="5555" />
我没有足够的声誉,否则我会将其作为评论发布。