在JBoss AS7中调用mbean时出错

时间:2015-06-29 15:04:09

标签: java jboss7.x java-ee-6 jmx mbeans

我正在尝试使用以下代码为JBoss应用程序调用mbean:

    MBeanServer mBeanServer =  ManagementFactory.getPlatformMBeanServer();           

            ObjectName namingName = ObjectName.getInstance("naming"+namingPort+":type=rmiregistry");
        if (mBeanServer.isRegistered( namingName))
               mBeanServer.unregisterMBean( namingName);

            mBeanServer.createMBean( "mx4j.tools.naming.NamingService", namingName, null, new Object[] { new Integer(
               namingPort) }, new String[] { "int" });
            mBeanServer.invoke( namingName, "start", null, null);
            //namingPort = ((Integer)mBeanServer.getAttribute(namingName, "Port")).intValue();
            String jndiPath = "/jmxconnector";
            int port = 9999;  // management-native port

            String urlString = System.getProperty("jmx.service.url","service:jmx:remoting-jmx://127.0.0.1:" + port);
            JMXServiceURL serviceURL = new JMXServiceURL(urlString);

            //JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost/jndi/rmi://localhost:2099" + jndiPath);
            JMXServiceURL url = new JMXServiceURL(urlString);

            // Create and start the RMIConnectorServer
            JMXConnectorServer connectorServer = JMXConnectorServerFactory.newJMXConnectorServer( url, null,
               mBeanServer);
            connectorServer.start();

执行代码时,我在jboss控制台中遇到错误:

Caused by: java.lang.LinkageError: loader constraint violation: loader (instance of org/jboss/modules/ModuleClassLoader) previously initiated loading for a diff
erent type with name "javax/management/MBeanServer"
        at com.sample.app.mx4j.Mx4jStandaloneManagement.prepareMBeanServer(Mx4jStandaloneManagement.java:116) [sample-app.jar:]

        at com.sample.app.BaseManagement.getMBeanServer(Unknown Source) [sample-app.jar:]
        at com.sample.app.BaseManagement.unregisterMBean(Unknown Source) [sample-app.jar:]
        at com.sample.app.ManagedConnectionFactory.registerMBean(Unknown Source) [sample-app.jar:]
        at com.sample.app.ManagedConnectionFactory.<init>(Unknown Source) [sample-app.jar:]
        at com.sample.app.XAManagedConnectionFactory.<init>(Unknown Source) [sample-app.jar:]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.7.0_80]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [rt.jar:1.7.0_80]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [rt.jar:1.7.0_80]
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526) [rt.jar:1.7.0_80]
        at java.lang.Class.newInstance(Class.java:383) [rt.jar:1.7.0_80]
        at org.jboss.as.connector.services.resourceadapters.deployment.AbstractResourceAdapterDeploymentService$AbstractAS7RaDeployer.initAndInject(AbstractReso
urceAdapterDeploymentService.java:495)
        ... 9 more

错误的原因是什么?

0 个答案:

没有答案