Wednesday, December 18, 2013

Jmx Client – Weblogic

In this article we will write a sample JMX client for connecting to the Weblogic Instance. The following code gives us a start up in wiring more advanced scripts for handling the Weblogic Instance.

Here is the Code for connecting to the Weblogic Instance running on a Local host(Just change the details accordingly)

import java.util.Hashtable;
import java.util.Set;

public class JMXClient {

public static void main(String[] args) throws Exception {

        JMXConnector jmxCon = null;

        try {
            JMXServiceURL serviceUrl =
                new JMXServiceURL(

            System.out.println("Connecting to: " + serviceUrl);

            Hashtable env = new Hashtable();
            env.put(javax.naming.Context.SECURITY_PRINCIPAL, "weblogic");
            env.put(javax.naming.Context.SECURITY_CREDENTIALS, "welcome1");

            jmxCon = JMXConnectorFactory.newJMXConnector(serviceUrl, env);
            MBeanServerConnection con = jmxCon.getMBeanServerConnection();

            Set<ObjectName> mbeans = con.queryNames(null, null);
            for (ObjectName mbeanName : mbeans) {
        finally {
            if (jmxCon != null)

The Jmx URL is the important line the whole code,

JMXServiceURL serviceUrl = new JMXServiceURL(

The available Protocols that can be to connect to the remove machines are IIOP,T3,RMI.In the above code we use IIOP to connect to the Weblogic Instance.

The Port and IP details can be obtained from the config file if we don’t know . The config file is located at WL_INSTANCE/config/config.xml file.

The Server details are laid out as

Make sure you get the correct details regarding the server. There are information in the config.xml file that says about many servers configured.

The MBeanServer to connect to: "". This identifies WebLogic's "Runtime" MBeanServer. This is the MBeanServer available from any WebLogic process, and that contains both WebLogic and user MBeans.

            Hashtable env = new Hashtable();
            env.put(javax.naming.Context.SECURITY_PRINCIPAL, "weblogic");
            env.put(javax.naming.Context.SECURITY_CREDENTIALS, "weblogic1");

The above code specifies properties associated with the connection. "" identifies the package implementing WebLogic's client side connector code. For instance the 't3' or 'iiop' client connector.
"weblogic" and "weblogic1" are the credentials associated with the user originating the JMX connection.
The rest of the code says about retrieving ObjectNames for the MBeans registered in the Runtime MBean Server.These will be displayed on console
Compiling the Code
Since we don’t have any Dependency with the weblogic files, the compilations goes fine.

Running the Code
For running the code, we need some classes from the weblogic. Executing the code requires to add WebLogic client side classes to the execution ClassPath. We need to include the WebLogic JMX connector client side classes.

java –classpath .:/root/Oracle/Middleware/wlserver_10.3/server/lib/wljmxclient.jar JMXClient

We can see a lot of Objects being displayed on the console.

Hope This sample code helps us to write more advanced jmx clients in accessing weblogic.

More To Come , Happy Learning J