码迷,mamicode.com
首页 > Web开发 > 详细

jmx远程连接weblogic

时间:2015-05-05 14:31:02      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:

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

}



jmx远程连接weblogic

标签:

原文地址:http://blog.csdn.net/xinyu1234567/article/details/45501231

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!