jmx远程连接weblogic

首先需要的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();
	   }

}



郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。