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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With