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!
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!