Server side configuration
-------------------------
Set these parameters in Generic JVM arguments.
-Djavax.management.builder.initial= -Dcom.sun.management.jmxremote
Specify these JVM custom properties
com.sun.management.jmxremote.authenticate false
com.sun.management.jmxremote.port 9004
com.sun.management.jmxremote.ssl false
Restart the server for the changes to take effect.
Java client program
-------------------
import java.util.Set;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
public class JMXTest {
public static void main(String[] args) {
JMXTest jmxtest = new JMXTest();
jmxtest.execute();
}
public void execute() {
MBeanServerConnection mbeanServerConnection = null;
JMXServiceURL serviceURL;
try {
serviceURL = new JMXServiceURL(
"service:jmx:rmi://{your_host_name}:2809/jndi/JMXConnector");
JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL);
mbeanServerConnection = jmxConnector.getMBeanServerConnection();
System.out.println("Successfully Connected!");
String query = "WebSphere:type=IlrBresModel,*";
ObjectName queryName = new ObjectName(query);
Set s = mbeanServerConnection.queryNames(queryName, null);
if (!s.isEmpty())
System.out.println(s.iterator().next());
else
System.out.println("MBean was not found");
} catch (Exception e) {
e.printStackTrace();
}
}
}
You should also have these two jars in the class path for the Java program to run.
com.ibm.ws.runtime_6.1.0.jar
ws_runtime.jar
Otherwise, runtime exceptions will be thrown.
No comments:
Post a Comment