Upgrading module dependency leads to ClassCastException on deployment

Tags: #<Tag:0x00007f0f22b8ca08>

Hello!

I am upgrading the radiology module to openmrs core 1.11.4.

Adding a dependency to hapi-structures-v231 which provides hl7 messages of version 2.3.1 leads following exception when I deploy the module:

org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from URL [jar:file:/tmp/tomcat7-tomcat7-tmp/1446200793163.openmrs-lib-cache/radiology/lib/radiology-api-0.1.0.0-dev-SNAPSHOT.jar!/moduleApplicationContext.xml]; nested exception is java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory

(see full log at http://pastebin.com/TP36zhaU)

The module compiles and tests run fine. However when I deploy it I get above exception.

Following post http://stackoverflow.com/questions/20404951/org-apache-xerces-jaxp-documentbuilderfactoryimpl-incompatible-with-javax-xml-pa tells me that I need to make sure that I don’t have multiple versions of Xerces

If I remove all my hl7 related classes and the dependency to hapi-structures-v231 I can deploy the module. So this must be it.

Does anybody have an idea/steps I can take to resolve this?


Deploying on:

OS: Ubuntu 14.04 64bit Java: Open JDK 1.7.0_85 Tomcat: 7 (package 7.0.52-1ubuntu0.3) Mysql: 5.5.46

Dependency I added to the root pom.xml

  	<dependency>
  		<groupId>ca.uhn.hapi</groupId>
  		<artifactId>hapi-structures-v231</artifactId>
  		<version>2.0</version>
  	</dependency>

mvn dependency:tree on the radiology module root gives: http://pastebin.com/u9u3Lz9X

found it :smile:

I needed to exclude any jars which were integrated into the omod through the new dependency, since the hapi-structures-v231.jar comes with its own xerces jar which is already coming with openmrs-core. so this is where the confusion came from.

so the root pom.xml now looks like this:

  	<dependency>
  		<groupId>ca.uhn.hapi</groupId>
  		<artifactId>hapi-structures-v231</artifactId>
  		<version>${hapiVersion}</version>
  		<exclusions>
  			<exclusion>
  				<groupId>*</groupId>
  				<artifactId>*</artifactId>
  			</exclusion>
  		</exclusions>
  	</dependency>
  </dependencies>
1 Like