PDA

View Full Version : Trouble with JDK 1.4, MX4J, & MC4J



cunparis
Mar 22nd, 2006, 10:07 AM
I've read the reference documentation, most of the posts here, and I still cannot get this to work. First question, if I use:



<bean id="serverConnector"
class="org.springframework.jmx.support.ConnectorServerFac toryBean">
<property name="objectName" value="connector:name=rmi" />
<property name="serviceUrl"
value="service:jmx:rmi://localhost/jndi/rmi://localhost:1099/myconnector" />

<property name="threaded" value="true" />
<property name="daemon" value="true" />
<property name="server">
<ref local="mbeanServer" />
</property>
</bean>

<bean id="registry"
class="org.springframework.remoting.rmi.RmiRegistryFactor yBean">
<property name="port" value="1099" />
</bean>


Will that only work for JDK 1.5? I get a class not found exception on javax/management/remote/JMXServiceURL which I understand is new for JDK 1.5.

Ok, so back to the reference documentation, here is my spring conf:



<beans default-lazy-init="false">

<bean id="testDispatcherSinglethreaded"
class="canal.det.service.workflow.common.TestDispatcherSi nglethreaded"
lazy-init="false" init-method="demarrer">
<constructor-arg>
<value>testDispatcherSinglethreaded</value>
</constructor-arg>
<constructor-arg>
<value>5</value>
</constructor-arg>
</bean>

<bean id="mbeanServer"
class="org.springframework.jmx.support.MBeanServerFactory Bean">
</bean>

<bean id="exporter"
class="org.springframework.jmx.export.MBeanExporter">
<property name="autodetect" value="true" />
<property name="beans">
<map>
<entry key="bean:name=testDispatcherSinglethreaded1"
value-ref="testDispatcherSinglethreaded" />
</map>
</property>
<property name="server" ref="mbeanServer" />
</bean>
</beans>


The application runs fine, but I cannot connect to it with MC4J. I see that MC4J says the MX4J connector is only for 1.x and for 2.x I should use the JSR 160 connector. But that is what I tried to do in the first code example and that gives me the class not found exception!

Could someone please tell me what I should put in my spring conf and how I connect with MC4J?

Thanks,
Michael

Costin Leau
Mar 22nd, 2006, 10:47 AM
JSR 160 represents the jmx remote facilities (the javax/management/remote pakage). JDK 1.4 doesn't contain any JMX support (like JDK 1.5) and you need to add the JMX library in the classpath. MX4J has good support for JMX remoting (JSR 160) and I assume in your case you did not put the relevant jar(mx4j-remote.jar I think) in the classpath.

From MX4J home page:


MX4J is a project to build an Open Source implementation of the Java(TM) Management Extensions (JMX) and of the JMX Remote API (JSR 160) specifications, and to build tools relating to JMX.

cunparis
Mar 22nd, 2006, 11:43 AM
JSR 160 represents the jmx remote facilities (the javax/management/remote pakage). JDK 1.4 doesn't contain any JMX support (like JDK 1.5) and you need to add the JMX library in the classpath. MX4J has good support for JMX remoting (JSR 160) and I assume in your case you did not put the relevant jar(mx4j-remote.jar I think) in the classpath.

From MX4J home page:

You are correct, I added the jar (mx4j-remote-3.0.1.jar) but I still get:



Caused by: java.lang.NoClassDefFoundError: javax/management/remote/JMXServiceURL
at org.springframework.jmx.support.ConnectorServerFac toryBean.afterPropertiesSet()V(ConnectorServerFact oryBean.java:153)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Ljava/lang/String;Ljava/lang/Object;Lorg/springframework/beans/factory/support/RootBeanDefinition;)V(AbstractAutowireCapableBeanF actory.java:1091)
at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(Ljava/lang/String;Lorg/springframework/beans/factory/support/RootBeanDefinition;[Ljava/lang/Object;)Ljava/lang/Object;(AbstractAutowireCapableBeanFactory.java:39 6)
... 28 more


I don't understand how I can get this when it's it's my classpath!

Costin Leau
Mar 22nd, 2006, 11:54 AM
Clean the classpath and make sure you have all the required jar - mx4j remote might require some other jar or the class mentioned above might be in a different archive. Your problem is obvious - the class is not found - however, you need to find why your jars are not read or what location is actually used.

cunparis
Mar 23rd, 2006, 03:05 AM
Clean the classpath and make sure you have all the required jar - mx4j remote might require some other jar or the class mentioned above might be in a different archive. Your problem is obvious - the class is not found - however, you need to find why your jars are not read or what location is actually used.

I'm getting the mx4j remote jar via Maven, so if it requires another jar maven should get that too. And if another jar was missing, wouldn't the error state the missing jar?

I've only seen something like this when something prevents the classloader from loading the jar, like an error in a static block.

Very strange.

cunparis
Mar 23rd, 2006, 06:22 AM
I'm getting the mx4j remote jar via Maven, so if it requires another jar maven should get that too. And if another jar was missing, wouldn't the error state the missing jar?

I've only seen something like this when something prevents the classloader from loading the jar, like an error in a static block.

Very strange.

It turned out to be a problem with the classpath and the order of the jars. Complicated even further because I'm using the Maven Eclipse plugin. I ended up having to rename the jar and add it to my project manually, putting it first in the list for the classpath.

-Michael