Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2255

ClassLoader problem when creating a GroovyMBean for a remote service

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1-rc-1
    • 1.1-rc-3
    • groovy-jdk
    • None
    • WindowsXP, Java 5 and Java 6

    Description

      Trying to connect to a MBean in a remote VM with the following script:

      import javax.management.ObjectName
      import javax.management.remote.JMXConnectorFactory as JmxFactory
      import javax.management.remote.JMXServiceURL as JmxUrl
      
      def serverUrl = new JmxUrl('service:jmx:rmi:///jndi/rmi://localhost:9000/jmxrmi')
      def server = JmxFactory.connect(serverUrl).mBeanServerConnection
      def myObject = new GroovyMBean(server, 'foo:name=bar')
      

      causes the following error when instantiating the GroovyMBean:

      Caught: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: groovy.util.GroovyMBean(
      javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection, java.lang.String)
              at jmxtest.run(jmxtest.groovy:9)
              at jmxtest.main(jmxtest.groovy)
      

      After doing some investigation I discovered that this is a class loader problem. The constructor does exist, but the MBeanServerConnection returned by JMX is loaded by the root class loader from rt.jar while Groovy looks for the MBeanServerConnection loaded by the groovy class loader from mx4j.jar. This can be confirmed by deleting mx4j.jar, which solves the problem.

      The more general problem here is the coexistence of the same class from two classloaders. Maybe the groovy class loader should first delegate to the bootstrap class loader. But I don't know internal details, so this might not make senss.

      Attachments

        Activity

          People

            paulk Paul King
            bcalmac@gmail.com Bogdan Calmac
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: