1
我想使用下面的簡單代碼在本地調用JMX服務。它在JConsole中可以正常工作,但是在命令行下它會在粘貼代碼的最後一行拋出異常。本地JMX調用失敗,ClassCastException
String serviceURL = "service:jmx:rmi:///jndi/rmi://localhost:" + configuration.getJmxPort();
String[] credentials = new String[]{configuration.getUsername(), configuration.getPassword()};
Map<String, String[]> attributes = new HashMap<String, String[]>();
attributes.put("jmx.remote.credentials", credentials);
JMXServiceURL jmxUrl = new JMXServiceURL(serviceURL);
jmxCon = JMXConnectorFactory.connect(jmxUrl, attributes);
堆棧跟蹤看起來是這樣的:
java.lang.ClassCastException: com.sun.jndi.rmi.registry.RegistryContext cannot be cast to javax.management.remote.rmi.RMIServer
at javax.management.remote.rmi.RMIConnector.narrowJRMPServer(RMIConnector.java:1897)
at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1892)
at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1856)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:257)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
at com.aaa.aaa.aaa.jmx.AaaJmxClient.main(AaaJmxClient.java:36)
權......這是簡單的。謝謝。 – Lukasz