两种Java代码实现方法:
通过jmx rmi 连接:
HashMap env = new HashMap(1);
final String[] credentials = new String[] { "admin", "adminadmin" };
env.put( JMXConnector.CREDENTIALS, credentials );
// so our JMXConnectorProvider may be found
//env.put( JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "com.sun.enterprise.admin.jmx.remote.protocol" );
JMXServiceURL serviceURL = new JMXServiceURL( "service:jmx:rmi:///jndi/rmi://localhost:8686/management/rmi-jmx-connector");
JMXConnector connector = JMXConnectorFactory.connect(serviceURL , env);
MBeanServerConnection connection = connector.getMBeanServerConnection();
Object o = connection.invoke(new ObjectName("com.sun.appserv:type=domain,category=config"), "getName", new Object[]{}, new String[]{});
System.out.println(o);
通过jmx http连接
HashMap env = new HashMap(4);
env.put( "com.sun.enterprise.as.http.auth", "BASIC" );
env.put( "USER", "admin" );
env.put( "PASSWORD", "adminadmin" );
env.put( JMXConnectorFactory.PROTOCOL_PROVIDER_PACKAGES, "com.sun.enterprise.admin.jmx.remote.protocol" );
JMXServiceURL serviceURL = new JMXServiceURL("s1ashttp", "localhost", 4848);
final JMXConnector conn = JMXConnectorFactory.connect( serviceURL, env );
MBeanServerConnection connection = conn.getMBeanServerConnection();
Object o = connection.invoke(new ObjectName("com.sun.appserv:type=domain,category=config"), "getName", new Object[]{}, new String[]{});
System.out.println(o);
Good Luck!
Yours Matthew!
posted on 2010-03-29 15:42
x.matthew 阅读(2525)
评论(0) 编辑 收藏 所属分类:
Best Practise(JDK API)