标签:
首先需要的jar包
其次代码如下:
package com.test; import java.io.IOException; import java.net.MalformedURLException; import java.util.Hashtable; import javax.management.MBeanServerConnection; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; import javax.naming.Context; public class MyConnection { private static JMXConnector connector; //private static final ObjectName service; /* * 实例化与 Domain Runtime MBean Server 的连接。 */ public static void initConnection(String hostname, String portString, String username, String password) throws IOException, MalformedURLException { String protocol = "t3"; Integer portInteger = Integer.valueOf(portString); int port = portInteger.intValue(); String jndiroot = "/jndi/"; String mserver = "weblogic.management.mbeanservers.runtime"; JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port, jndiroot + mserver); Hashtable h = new Hashtable(); h.put(Context.SECURITY_PRINCIPAL, username); h.put(Context.SECURITY_CREDENTIALS, password); h.put(JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "weblogic.management.remote"); connector = JMXConnectorFactory.connect(serviceURL, h); connector.getMBeanServerConnection(); } public static void main(String[] args) throws Exception { String hostname = "10.64.34.12"; String portString = "7001"; String username = "weblogic"; String password = "weblogic1"; MyConnection c= new MyConnection(); initConnection(hostname, portString, username, password); System.out.print(connector.toString()); connector.close(); } }
标签:
原文地址:http://blog.csdn.net/xinyu1234567/article/details/45501231