9

我用 POI 构建了一个 Grails 项目(包括 poi-3.7 和 poi-ooxml-3.7)。我已将这 2 个外部库添加到项目的 BuildConfig.groovy 文件中的依赖项块中。我编译的时候没有什么奇怪的。但是当我为该项目调用命令“run-app”时,下面的堆栈跟踪发生了错误:

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  

这是我的配置:

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')  
    }  

我该怎么做才能解决这个问题?太感谢了!

4

5 回答 5

11

这是我们在来回几个小时后终于解决的问题。简而言之,从 poi 中排除 xmlbeans 并创建另一个 xmlbeans jar 并删除有问题的类。这是驱除邪恶链接错误的咒语。

  • 修改 BuildConfig.groovy

    dependencies {
       compile ('org.apache.poi:poi-ooxml:3.6') {excludes "xmlbeans"}
    }
  • 提取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

  • 删除违规类包

    cd org
    rm -rf w3c/

  • 重新创建罐子

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

  • 将 jar 复制到您的项目库中

    cp xmlbean-2.3.0.jar your_grails_project/lib/。

  • 展现爱

    点击回答向上箭头。:)

于 2011-08-11T13:39:54.460 回答
1

POI 的依赖项之一(xmlbeans)和 grails 之间存在冲突。您可以按如下方式排除它:

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

以下链接有助于追踪问题:

于 2011-06-20T12:15:01.133 回答
1

我有一个类似的问题,这是一个缓存问题。我删除了 .grails 和 .ivy2 目录(在主目录下),它解决了我的麻烦。祝你好运。

于 2011-07-27T12:47:59.873 回答
1

我想我解决了这个问题。由于 Perm gen 空间/“grails run-app”期间内存不足,Steve Wall 的解决方案不想在 grails 2.0.0 上为我工作。

BuildConfig.groovy

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

然后下载xbean-2.1.0.jar,应用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/

对我来说效果很好!祝你好运!

于 2011-12-29T19:09:39.883 回答
0

我不知道这是否能解决你的问题,但我猜你对 POI 的依赖可能应该是编译时的。尝试将您的依赖项更改为:

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')  
}  
于 2011-05-23T13:11:29.807 回答