【问题标题】:java.lang.NoClassDefFoundError: org/apache/poi/POIXMLDocumentjava.lang.NoClassDefFoundError: org/apache/poi/POIXMLDocument
【发布时间】:2018-05-24 21:40:27
【问题描述】:

我正在尝试使用作为包部署在 Karaf 中的 Apache POI 读取 Excel。

按订单使用的 POI 版本:

  • poi-3.11.jar
  • poi-ooxml-3.11.jar
  • poi-ooxml-schemas-3.11.jar

feature.xml sn-p(用于在 Karaf 中包装捆绑包):

<bundle>wrap:mvn:org.apache.poi/poi/3.11</bundle>
<bundle>wrap:mvn:org.apache.poi/poi-ooxml/3.11</bundle>
<bundle>wrap:mvn:org.apache.poi/poi-ooxml-schemas/3.11</bundle>

pom.xml(依赖罐子)

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>3.11<version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.11<version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml-schemas</artifactId>
    <version>3.11</version>
</dependency>

以上项目中用作依赖项的 jar 以及 Karaf 中的捆绑包。

尝试了servicemix 版本的 POI。但这也无济于事。

我了解NoClassDefFoundError 是运行时错误,这是在运行时找不到类时引起的。请给我解决这个问题。

堆栈跟踪:

java.lang.NoClassDefFoundError: org/apache/poi/POIXMLDocument
    at java.lang.ClassLoader.defineClass1(Native Method)[:1.8.0_25]
    at java.lang.ClassLoader.defineClass(Unknown Source)[:1.8.0_25]
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.findClass(BundleWiringImpl.java:2128)
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1432)
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:72)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1843)
    at java.lang.ClassLoader.loadClass(Unknown Source)[:1.8.0_25]
    at org.apache.felix.framework.BundleWiringImpl.getClassByDelegation(BundleWiringImpl.java:1317)
    at org.apache.felix.framework.BundleWiringImpl.searchImports(BundleWiringImpl.java:1481)
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1427)
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:72)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1843)
    at java.lang.ClassLoader.loadClass(Unknown Source)[:1.8.0_25]

【问题讨论】:

  • 您的类路径中似乎有同一个类的多个版本。
  • 您为什么使用旧版本的 Apache POI?如果您只是获取最新的 Apache Servicemix POI 捆绑包会发生什么?

标签: java excel apache-poi apache-karaf xssf


【解决方案1】:

我在一个项目中工作过,该项目使用 servicemix bundle 而不是直接 POI。

<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi/3.15_1</bundle>

【讨论】:

  • 在我的例子中,我的包已经在使用纯 POI。所以我现在不能转到 servicemix。
  • 您是否将包从 POI 导入到您的清单中?您需要然后导入或使用动态导入,例如:*
猜你喜欢
  • 2011-09-21
  • 2017-10-26
  • 2019-05-27
  • 1970-01-01
  • 2019-02-22
  • 2019-06-14
  • 1970-01-01
  • 2016-03-29
  • 1970-01-01
相关资源
最近更新 更多