Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.1-rc-1
-
Fix Version/s: 1.1-rc-3
-
Component/s: groovy-jdk
-
Labels:None
-
Environment:WindowsXP, Java 5 and Java 6
-
Number of attachments :
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.
Hi Bogdan,
This is not really an issue related to GroovyMeans so I am going to mark it resolved. We bundle mx4j.jar in the groovy distribution because none is included in Java 1.4. In Java 1.5+, JMX client capability is included and will be in conflict with the mx4j.jar library. The solution is simply to remove that jar from your distribution if you are using Groovy on a 1.5+ JVM. Or alternatively, invoke your application with a custom classpath set, e.g.:
C:\jdk1.6.0_03\bin\java -classpath groovy-all-1.1-final-SNAPSHOT.jar groovy.lang.GroovyShell TomcatInfo.groovyI discussion has been had on how to handle this sort of thing in a general way. It affects more than just MBeans. We will likely have 1.4, 1.5, 1.6 specific libraries at some point in the future and we will load the appropriate libraries depending on the JVM version discovered at runtime.
Please feel to open a more generic issue if you want to track when that multi-JVM libraries capability will be complete. Though at this stage it is only an idea and may change/evolve in on-going discussion.