Thursday, July 29, 2010

Grails LinkageError for SAXParseException

I ran "grails run-app" for the app that I've been working on and was greeted with the following :

java.lang.LinkageError: loader constraint violation: loader (instance of <bootlo
ader>) previously initiated loading for a different type with name "org/xml/sax/
SAXParseException"
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
at java.lang.Class.getDeclaredMethods(Class.java:1791)
at java.security.AccessController.doPrivileged(Native Method)
at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:4
6)
at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
at grails.util.PluginBuildSettings.getPluginInfos(PluginBuildSettings.gr
oovy:127)
at grails.util.PluginBuildSettings.getPluginInfos(PluginBuildSettings.gr
oovy)
at grails.util.PluginBuildSettings$getPluginInfos.callCurrent(Unknown So
urce)
at grails.util.PluginBuildSettings.getPluginInfo(PluginBuildSettings.gro
ovy:164)
at grails.util.PluginBuildSettings$getPluginInfo.callCurrent(Unknown Sou
rce)
at grails.util.PluginBuildSettings.getPluginInfoForSource(PluginBuildSet
tings.groovy:202)
at org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTran
sformationVisitor.java:303)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(Compil
ationUnit.java:832)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(Compilat
ionUnit.java:519)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(Co
mpilationUnit.java:495)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.j
ava:472)
at _GrailsEvents_groovy.run(_GrailsEvents_groovy:54)
at _GrailsEvents_groovy$run.call(Unknown Source)
at _GrailsClean_groovy$run.call(Unknown Source)
at _GrailsClean_groovy.run(_GrailsClean_groovy:29)
at _GrailsClean_groovy$run.call(Unknown Source)
$
at _GrailsPlugins_groovy.run(_GrailsPlugins_groovy:32)
at _GrailsPlugins_groovy$run.call(Unknown Source)
at _GrailsRun_groovy$run.call(Unknown Source)
at _GrailsRun_groovy.run(_GrailsRun_groovy:31)
at _GrailsRun_groovy$run.call(Unknown Source)
at RunApp.run(RunApp.groovy:25)
at RunApp$run.call(Unknown Source)
at gant.Gant.prepareTargets(Gant.groovy:606)
Error loading event script from file [PATH_TO_GRAILS\.grails
\1.3.1\projects\PROJECT_NAME\plugins\code-coverage-1.1.8\scripts\_Events.gr
oovy] loader constraint violation: loader (instance of <bootloader>) previously
initiated loading for a different type with name "org/xml/sax/SAXParseException"

Grails had done some sort of update that I didn't pay a lot of attention to. I wondered if this had something to do with the update and will have to find out what went on later.

I found an entry on the Grails Jira dealing with the problem of xerces and Java 6. The suggested solution was to remove xml-apis-1.0.2.b2.jar.

I ran :
find . -name "*xml*"
find . -name "*api*"
from my project directory, my .grails directory and my .ivy directory. I found xml-apis-1.3.04.jar in my .ivy directory.

I ran jarscan against my project directory, .grails directory and .ivy directory and found 0 hits for SAXParseException.

I added :

    inherits("global") {
excludes "xml-apis"
}

To my BuildConfig.groovy file just below dependencies. The app ran.

5 comments:

-Eric said...

Ran into a similiar issue with Grails 1.3.6 and xerces. This fixed it:

inherits("global") {
excludes "xml-apis", "xmlParserAPIs"
}

jeremyrdavis said...

Eric,

Thanks for the added info.

Unknown said...

Didn't worked for me... I had to delete the xml-api .jar from the lib directory at .groovy folder and .ivy2 folder.

Kim said...

Hi All,

I have similar issue with my grails-gwt project. I am doing compile-gwt-modules with -verbose.
Please help me.


-----------------------------------
Errors
-----------------------------------
1st error

[Loaded org.apache.log4j.spi.ThrowableInformation from file:/C:/Documents%20and%20Settings/user_name/.ivy2/cache/log4j/log4j/jars/log4j-1.2.16.jar]
java.lang.LinkageError: loader constraint violation: loader (instance of ) previously initiated loading for a different type with name "org/xml/sax/SAXParseException"

[Loaded java_util_Iterator$next from __JVM_DefineClass__]
[Loaded org.codehaus.gant.GantBinding$_initializeGantBinding_closure5_closure14 from file:/C:/Java/eclipse-jee-helios-SR2-win32/grails-1.3.7/lib/gant_groovy1.7-1.9.2.jar]

-----------------------------------
2nd error

-----------------------------------
[Loaded org.xml.sax.SAXParseException from C:\Program Files\Java\jdk1.6.0_24\jre\lib\rt.jar]
Error executing script CompileGwtModules: loader constraint violation: loader (instance of ) previously initiated loading for a different type with name "org/xml/sax/SAXParseException"
java.lang.LinkageError: loader constraint violation: loader (instance of ) previously initiated loading for a different type with name "org/xml/sax/SAXParseException"



I did some research and tried below options even though no success. Please reply asap.

1. delete .ivy2/cache but every time while doing clean or compile it is automatically creating .ivy2/cache so unable to delete it

2. I tried below in buildconfig.groovy
-----------------------------------
inherits("global") {
excludes 'xml-apis','xmlParserAPIs','xercesImpl'

}

compile ('org.grails:grails-core:1.3.7'){

excludes 'xml-apis','xmlParserAPIs','xercesImpl'


}

compile ('log4j:log4j:1.2.16'){

excludes 'xml-apis','xmlParserAPIs','xercesImpl'
}

3. added empty log4j and grails-core in .ivy2/cache and got some diff error with misiing other class

Unknown said...

Hello Kim

1. delete .grails/ folder
2. delete .groovy/ folder
3. delete .ivy2/ folder

then compile again. check if this solves.