9

I've built a Grails project with POI (include poi-3.7 and poi-ooxml-3.7). I've added these 2 external libraries to dependencies block in BuildConfig.groovy file of my project. There's nothing strange when I compiled it. But when I called the command "run-app" for that project, an error occured with below stacktrace:

Base Directory: <path-to-my-project>
Resolving dependencies...
Dependencies resolved in 5546ms.
Running script D:\_TOOLS\STS\grails-1.3.5\scripts\RunApp.groovy
Environment set to development
Running Grails application..
2011-05-23 18:51:01,225 [main] ERROR context.GrailsContextLoader  - Error executing bootstraps: java.lang.LinkageError: loader constraint violation: loader (instance of <bootloader>) previously initiated loading for a different type with name "org/w3c/dom/DOMConfiguration"
org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.LinkageError: loader constraint violation: loader (instance of <bootloader>) previously initiated loading for a different type with name "org/w3c/dom/DOMConfiguration"
    at grails.spring.BeanBuilder.invokeBeanDefiningClosure(BeanBuilder.java:723)
    at grails.spring.BeanBuilder.beans(BeanBuilder.java:573)
    at grails.spring.BeanBuilder.invokeMethod(BeanBuilder.java:519)
    at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:212)
    at grails.web.container.EmbeddableServer$start.call(Unknown Source)
    at RunApp$_run_closure5_closure12.doCall(RunApp:158)
    at RunApp$_run_closure5_closure12.doCall(RunApp)
    at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:280)
    at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
    at RunApp$_run_closure5.doCall(RunApp:149)
    at RunApp$_run_closure5.call(RunApp)
    at RunApp.runInline(RunApp:116)
    at RunApp.this$4$runInline(RunApp)
    at RunApp$_run_closure1.doCall(RunApp:59)
    at RunApp$_run_closure1.doCall(RunApp:33)
    at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
    at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
    at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
    at gant.Gant.withBuildListeners(Gant.groovy:427)
    at gant.Gant.this$2$withBuildListeners(Gant.groovy)
    at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
    at gant.Gant.dispatch(Gant.groovy:415)
    at gant.Gant.this$2$dispatch(Gant.groovy)
    at gant.Gant.invokeMethod(Gant.groovy)
    at gant.Gant.executeTargets(Gant.groovy:590)
    at gant.Gant.executeTargets(Gant.groovy:589)

Caused by: java.lang.LinkageError: loader constraint violation: loader (instance of <bootloader>) previously initiated loading for a different type with name "org/w3c/dom/DOMConfiguration"
    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:46)
    at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
    at grails.spring.DynamicElementReader.invokeMethod(DynamicElementReader.groovy:121)
    ... 26 more  

And here is my configuration:

dependencies {  
        provided ('com.oracle:ojdbc6_g:11.2.0.1.0')  
        runtime ('org.apache.poi:poi:3.7', 'org.apache.poi:poi-ooxml:3.7')  
    }  

How can I do to make solve this? Thank you so much!

Đinh Hồng Châu
  • 5,300
  • 15
  • 53
  • 90
  • Hi ... i have same problem expect the type that is with name "javax/management/MBeanServer". I really don't know from where to start and it's driving me crazy. Can you give me any hint? – Rafael Feb 03 '15 at 13:55

5 Answers5

11

Here's the fix we finally came around to after several hours of going back and forth. In short, exclude xmlbeans from poi and create another xmlbeans jar with the offending class removed. Here's the incantation to exorcise the evil linkage error.

  • Modify BuildConfig.groovy

    dependencies {
       compile ('org.apache.poi:poi-ooxml:3.6') {excludes "xmlbeans"}
    }
  • Extract xmlbeans

    cd ~
    mkdir xmlbeantmp
    cd xmlbeantmp
    cp ~/.ivy2/cache/org.apache.xmlbeans/xmlbeans/jars/xmlbeans-2.3.0.jar .
    jar xf xmlbeans-2.3.0.jar

  • Remove offending class package

    cd org
    rm -rf w3c/

  • Recreate the jar

    cd ../
    rm xmlbean-2.3.0.jar
    jar cf xmlbean-2.3.0.jar *

  • Copy jar into your projects lib

    cp xmlbean-2.3.0.jar your_grails_project/lib/.

  • Show the love

    click answer up arrow. :)

Steve Wall
  • 1,842
  • 5
  • 21
  • 50
1

There's a conflict between one of POI's dependencies (xmlbeans) and grails. You can exclude it as follows:

dependencies {
    compile('org.apache.poi:poi-ooxml:3.7') { excludes "xmlbeans" }
}

The following links were useful in tracking down the problem:

tomc
  • 1,458
  • 1
  • 10
  • 16
  • Yes, we can exclude the dependency xmlbeans from poi-ooxml to start app successful, but we will get the ClassDefNotFoundException when running application. Because some classes in poi-ooxml actually depends on classes of xmlbeans jar. – Đinh Hồng Châu Jun 21 '11 at 10:49
1

I had a similar problem and it was a cache issue. I deleted the .grails and .ivy2 directory (under the home) and it solved my troubles. Good Luck.

Maver23
  • 11
  • 1
1

i suppose that i fix this problem. Solution of Steve Wall want not work for me on grails 2.0.0 because of Perm gen space / Out of memory during "grails run-app".

BuildConfig.groovy

....
inherits("global") {
    excludes 'xmlbeans', 'xbean'
}
....
runtime 'xmlbeans:xmlpublic:2.1.0'
runtime 'org.apache.poi:poi-ooxml:3.7'
....

Then download xbean-2.1.0.jar, and apply solution of Steve Wall:

jar xf xbean-2.1.0.jar
cd org
rm -rf w3c/
cd ..
rm xbean-2.1.0.jar
jar cf xbean-2.1.0.patched.jar *
cp xbean-2.1.0.patched.jar your_grails_project/lib/

For me it works fine! Good luck!

jenk
  • 1,043
  • 7
  • 8
0

I don't know if this will fix your problem, but my guess is that your depency on POI should probably be compile-time. Try changing your dependencies to:

dependencies {  
    provided ('com.oracle:ojdbc6_g:11.2.0.1.0')  
    compile ('org.apache.poi:poi:3.7', 'org.apache.poi:poi-ooxml:3.7')  
}  
Dónal
  • 185,044
  • 174
  • 569
  • 824
  • Yes, thank you for your suggestion. I tried it, but it still doesn't work. With the error: java.lang.LinkageError: loader constraint violation: loader (instance of ) previously initiated loading for a different type with name "org/w3c/dom/DOMConfiguration", I've checked it again, and there are 2 classes DOMConfiguration in 2 different jar packages: xmlbeans-2.3.0.jar and in jdk. So I think that is the main reason which causes the error. But I don't know how to resolve, because I need the poi-ooxml library for my project while xmlbeans-2.3. is one of its dependencies. – Đinh Hồng Châu May 24 '11 at 01:40
  • I have an idea to resolve this, that is excluding the package org.w3c.dom in xmlbeans jar, but I don't know what is the correct syntax to do this in BuildConfig. Here is my trial: provided ('com.oracle:ojdbc6_g:11.2.0.1.0') runtime ('org.apache.poi:poi:3.7', 'org.apache.poi:poi-ooxml:3.7') { excludes "org.w3c.dom" }. But it does not work – Đinh Hồng Châu May 24 '11 at 02:24