Monday, February 22, 2010

Grails and Xerces problem

Just fixed an annoyed bug with my grails project. I'm using openid4java (with spring security) and it required xerces, without it throws following error:

java.lang.ClassNotFoundException: org.openid4java.util.OpenID4JavaDOMParser


Class OpenID4JavaDOMParser is exists at classpath, of course. But it uses xerces, and if you just simple add maven dependency for xerces, the grails (version 1.2.1) fails with the following error:

java.lang.LinkageError: loader constraint violation: loader (instance of ) previously initiated loading for a different type with name "org/w3c/dom/NamedNodeMap"


After long investigations I found that it's because of xml-apis library. You need to exclude it from dependencies at your pom.xml as:

<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>


But remember that it declared as dependency for many libraries, like xercesImpl, openxri-client, nekohtml, etc. Check your maven dependencies by mvn dependency:tree to ensure there are no any xml-apis usage. And make a mvn clean after this.

I had spent about 3 days for this problem, and hope that this will help someone :)