AFAIK, it is not possible to get the JMXConnectorServer
which is automatically created by getPlatformMBeanServer()
, but you can make the platform MBean server use a connector server instance that you created yourself.
When you do this, it is important that the com.sun.management.jmxremote*
system properties are unset, so that the platform MBean server does not automatically set up a connector server.
Example: If you configured the JMX remote access with the system properties
-Dcom.sun.management.jmxremote.port=1919
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
remove these system properties and configure your own connector server programmatically with the following code:
int jmxPort = 1919;
LocateRegistry.createRegistry(jmxPort);
MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
// or: MBeanServer beanServer = MBeanServerFactory.createMBeanServer(); // doesn't register the default platform MBeans
JMXServiceURL jmxUrl
= new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + jmxPort + "/jmxrmi");
JMXConnectorServer connectorServer
= JMXConnectorServerFactory.newJMXConnectorServer(jmxUrl, null, beanServer);
connectorServer.start();
This tech note from Oracle contains another example for a manual connector server setup when you want to use authentication and SSL.