java.lang.NoClassDefFoundError: org/jaxen/JaxenException in module

I am using dom4j to parse MRRT Templates in radiology-fhir-support module that I’m working on alongwith @judy

I am running the module against OpenMRS 1.11.4 on Tomcat 7 and Ubuntu 15.10 and here is my pom file :

Whenever I install/update the module, Context.getService({Any service in my module}.class) returns null and throws an APIException stating that the service was not found. This however gets fixed on restarting tomcat. I’d assume that OpenMRS was not able to find the openmrs-module-radiology-fhir-support-api.jar in the /lib folder (which is present) and therefore restarting tomcat reloads the application container and refreshes the classpath.

After this, whenever I execute any Service Layer method that uses dom4j api, I get a java.lang.NoClassDefFoundError: org/jaxen/JaxenException . Here are the logs Here are the methods that use the dom4j API :

I understand this error means that JaxenException is not on my classpath. To confirm this, I performed the following steps:

  1. mvn package the module. Go to /omod/taget and confirmed that the module’s omod file contains jaxen-1.1.6.jar in the /lib subdirectory.
  2. I extracted that jaxen-1.1.6.jar and it did contain /org/jaxen.JaxenException.class ruling out possibility of an invalid jar file
  3. I verified that module’s omod is present in /var/lib/OpenMRS/modules/ contains jaxen-1.1.6.jar in the /lib subdirectory

I cannot figure out why jaxen-1.1.6.jar is not on the classpath. :confused: and I always get the exact same error after playing around with the pom. The interesting thing is that when the exact same Service Methods are executed in Tests, they run perfectly. What could I be missing?

To work-around this issue in the most unethical way, I placed the jaxen-1.1.6.jar in /var/lib/tomcat7/webapps/openmrs/WEB-INF/libs and everything in the module works correctly.

Is this committed on github for me to try reproduce locally?

Just for curiosity, why don’t you use a Java parser included in the JVM like JAXB or stAX ? Or even XStream, used in other OpenMRS modules ?

If you want to use XPath as a query language, you don’t need the Jaxen library because it’s already in the API:

According to this question the library must be located in the app server library folder.

1 Like

@dkayiwa The APIException: Service not found was fixed by adding the “< scope>provided< /scope>” for fhir-api dependency in the pom.xml for the module. I still get the JaxenException though. Here’s the code for the module : You can directly run the module in docker with : mvn clean package docker:build docker:run Here are some other instructions that might be helpful in trying it out :

Thanks for the recommendations and the links @lluismf :slight_smile:

I already have quite some code using Dom4j. When I get some time, I will definitely consider migrating if the jaxen exception persists.

The stack overflow link works. But as mentioned in the second comment to this thread, I have to copy the jar manually, which kinda adds an additional and non-conventional step in the module installation process.

I noticed the your scope is compile, have you tried using provided?

@ssmusoke that gives the same error. In case of using scope as provided, jaxen-1.1.6.jar is not present in the packaged omod file. When I use compile as the scope, jaxen-1.1.6.jar is present in the omod file. But when module is installed, it does not get copied to /var/lib/tomcat7/webapps/openmrs/WEB-INF/lib/ directory. When I manually place the jar in that directly, it works :stuck_out_tongue:

@maany would i just compile this module and drop in my running openmrs instance to reproduce?

Hello @dkayiwa

Am facing same challenge, i am using xmlrpc on my module but am getting NoClassDefFoundError when i deploy my module to openmrs, any soln?

You would need to give details of how to locally reproduce.