I am hoping this is the proper forum for my problem. I have enabled the JmxRemoteLifeCycleListener and able to connect to tomcat 7 using jconsole etc. using the following url.

service:jmx:rmi://10.92.12.88:10002/jndi/rmi://10.92.12.88:10001/jmxrmi

However as soon as I try to connect from my own application using the code example below I get an error the following error. I figure I need to configure the InitialContextFactory, but I don't know what class I should specify. I also don't understand how jconsole is able to connect without any additional configuration, but my client is not.

Perhaps somebody has some pointers on how to make remote JMX connections programmatically.

------------------------------------------------------------------------

java.io.IOException : Failed to retrieve RMIServer stub: javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.impl.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.impl.SerialInitContextFactory] java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.impl.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.impl.SerialInitContextFactory] at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:369) at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:270)

Caused by: javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.impl.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.impl.SerialInitContextFactory] at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
    at javax.naming.InitialContext.init(InitialContext.java:244)
    at javax.naming.InitialContext.<init>(InitialContext.java:216)
at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1927) at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1896) at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:287)
    ... 3 more
Caused by: java.lang.ClassNotFoundException: com.sun.enterprise.naming.impl.SerialInitContextFactory
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:340)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:72) at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:61) at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:672)
    ... 9 more

------------------------------------------------------------------------

Code extract:

      Map<String, String[]> env = new HashMap<String, String[]>();
      String[] credentials = new String[]
      {
        "username", "password"
      };
      env.put(JMXConnector.CREDENTIALS, credentials);
String url = "service:jmx:rmi://10.92.12.88:10002/jndi/rmi://10.92.12.88:10001/jmxrmi";
      serviceUrl = new JMXServiceURL(url);
JMXConnector connector = JMXConnectorFactory.connect(serviceUrl, env); MBeanServerConnection connection = connector.getMBeanServerConnection();
      ObjectName servicename = new ObjectName("java.lang:type=Runtime");
      ObjectInstance instance = connection.getObjectInstance(servicename);



Reply via email to