Search code examples
grailsmx4j

Grails run-app not starting when adding mx4j dependency


I am working on a Grails project that has a transitive dependency on mx4j jar. I cannot avoid the dependency which is using the mx4j jar, and I have used this jar in the provided scope.

But whenever I run my application using grails run-app I get the following error:

Error loader constraint violation: loader (instance of ) previously initiated loading for a different type with name "javax/management/MBeanServer" java.lang.LinkageError: loader constraint violation: loader (instance of ) previously initiated loading for a different type with name "javax/management/MBeanServer" at javax.management.MBeanServerBuilder.newMBeanServerDelegate(MBeanServerBuilder.java:49) at javax.management.MBeanServerFactory.newMBeanServer(MBeanServerFactory.java:302)

If I remove the provided 'mx4j:mx4j:3.0.2' dependency, I get a ClassNotFoundException on an mx4j Class.

I think the internal grails tomcat is loading "javax/management/MBeanServer" class and since it is also loaded via mx4j, it is causing the above issue. Is there anyway I can resolve this issue at the grails end? I cannot avoid the mx4j dependency in my project.


Solution

  • I could solve it. I removed the mx4j dependency and also excluded the dependency that was bringing in mx4j dependency from the original dependency I had added. When I removed mx4j I got the same ClassNotFoundException, but I avoided the dependency which was needing it. Some how all started working :)