JavaScript implementation: how to write beautiful conditional expression>>>
Project requirements: through JMX monitoring zookeeper, the effect is similar to jconsole, but presented in the form of web. In the process of using, when JMX in the web container connects to mbeanserver to obtain the connection, it always fails. The prompt message is: Java. Lang. classnotfoundexception: org. Apache. Naming. Java. Javaurlcontextfactory. But it can be accessed normally when calling through the main method
The code is as follows:
String jmxURL = "service:jmx:rmi:///jndi/rmi://" + ip + ":" + jmxport + "/jmxrmi";
// jmxurl
JMXServiceURL serviceURL = new JMXServiceURL(jmxURL);
Map<String, String[]> map = new HashMap<String, String[]>();
String[] credentials = new String[] { userName, password };
map.put("jmx.remote.credentials", credentials);
connector = JMXConnectorFactory.connect(serviceURL, map);
MBeanServerConnection mbsc = connector.getMBeanServerConnection();
After searching for information from the Internet, from an article( http://canofy.iteye.com/blog/758748 )The method to get mbeanserverconnection is modified, and then it can run normally. The modified code is as follows:
Registry registry = LocateRegistry.getRegistry(host, Integer.parseInt(port));
RMIServer stub = null;
if (stub == null) {
stub = (RMIServer) registry.lookup("jmxrmi");
}
Map<String, String[]> map = new HashMap<String, String[]>();
String[] credentials = new String[] { username, password };
map.put("jmx.remote.credentials", credentials);
connector = new RMIConnector(stub, null);
connector.connect(map);
mbsc = connector.getMBeanServerConnection();
There are two ways to get mbeanserverconnection. In general, both ways are OK. For some special applications, API means that the second method is best used
Similar Posts:
- MySQL database insert into statement with parameters Error
- Rabbitmq simple configuration and oserror: [errno 9] bad file descriptor problem
- [Solved] Error resolving template “XXX”, template might not exist or might not be accessible by any of the
- [Solved] Git Clone Error: The requested URL returned error: 403 error
- An error is reported when logging into harbor warehouse with docker login of other hosts
- [Solved] No converter found for return value of type: class org.json.JSONObject
- FW: Fix – Your Credentials Did not Work in Remote Desktop
- Laravel [1045] Solution Access denied for user’homestead’@’localhost’
- [Solved] Data codes related to ‘LDAP: error code 49’ wit…