java.lang.NoClassDefFoundError:org / apache / poi / xssf / usermodel / XSSFWorkbook

时间:2017-05-26 04:55:04

标签: java eclipse eclipse-plugin apache-poi eclipse-emf

我得到了这个例外,但我无法理解那里发生的事情。

因为在编译时我的类能够访问apache POI类,但是在运行时我的类抛出了他无法找到的异常

org.apache.poi.xssf.usermodel.XSSFWorkbook

直到网上提供的任何解决方案,我都尝试了所有方法,但没有理解我所缺少的内容。

奇怪的是,同样的代码和同一个Apache POI库在我朋友的日食上工作。我们都有相同的项目。不要理解那里发生了什么。

我检查了所有文件夹访问我所指的库。

如果您有任何建议,请分享。

我收到以下异常。

!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.NoClassDefFoundError: org/apache/poi/xssf/usermodel/XSSFWorkbook
    at com.herzog.pmide.mergedconfigxml.ui.editors.DocumentGenerator.prepareScadaIOListExcel(DocumentGenerator.java:94)
    at com.herzog.pmide.mergedconfigxml.ui.editors.DocumentGenerator.scadaIOList(DocumentGenerator.java:77)
    at com.herzog.pmide.mergedconfigxml.ui.actions.DocumentGeneratorAction.run(DocumentGeneratorAction.java:47)
    at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:253)
    at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:595)
    at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:511)
    at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:420)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4353)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1061)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4172)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3761)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1151)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:331)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1032)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:148)
    at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:636)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:331)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:579)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
    at com.herzog.pmide.application.Application.start(Application.java:20)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
Caused by: java.lang.ClassNotFoundException: org.apache.poi.xssf.usermodel.XSSFWorkbook cannot be found by com.herzog.pmide.mergedconfigxml.ui_1.0.0.qualifier
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:432)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:345)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:337)
    at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

MANIFEST.MF如下

    Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Ui
Bundle-SymbolicName: com.herzog.pmide.mergedconfigxml.ui;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.herzog.pmide.mergedconfigxml.ui.Activator
Bundle-Vendor: Example
Require-Bundle: org.eclipse.ui,
 org.eclipse.core.runtime,
 org.eclipse.core.resources,
 org.eclipse.emf.ecore.xmi,
 org.eclipse.emf.edit.ui,
 com.herzog.pmide.machinelib.model.edit,
 org.eclipse.ui.forms,
 org.eclipse.ui.workbench,
 org.eclipse.ui.ide,
 com.herzog.pmide.mergedconfigxml.model.edit,
 org.eclipse.gef,
 com.herzog.pmide.tools.importutility,
 com.herzog.pmide.machinelib.model,
 org.eclipse.swt,
 org.eclipse.emf.query,
 com.herzog.pmide.mergedconfigxml.model,
 org.eclipse.ui.editors,
 org.eclipse.emf.validation,
 org.eclipse.emf.validation.ui,
 org.slf4j.api,
 org.junit,
 org.eclipse.emf.compare,
 org.eclipse.emf.compare.edit,
 org.eclipse.emf.compare.ide.ui,
 org.eclipse.compare,
 org.apache.commons.io,
 org.eclipse.core.filesystem,
 de.vonloesch.pdf4Eclipse,
 de.vonloesch.pdf4eclipse.help,
 com.herzog.pmide.routingline.model
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Export-Package: com.herzog.pmide.mergedconfigxml.ui,
 com.herzog.pmide.mergedconfigxml.ui.editors.unitconfig,
 com.herzog.pmide.mergedconfigxml.ui.views
Bundle-Localization: OSGI-INF/l10n/message

build.properties如下

source.. = src/
output.. = bin/
bin.includes = META-INF/,\
               .,\
               plugin.xml,\
               icons/,\
               OSGI-INF/l10n/message.properties

1 个答案:

答案 0 :(得分:4)

插件只能访问包含在类包路径中的插件中包含的其他插件或包中的类。设置Java Build Path属性不会正确配置插件。

将所有需要的jar添加到插件中,通常将它们放在'lib'目录中。

更新build.properties以在'bin.includes'部分中包含这些jar。例如:

source.. = src/
output.. = bin/
bin.includes = META-INF/,\
               .,\
               plugin.properties,\
               plugin.xml,\
               lib/,\
               lib/jogg-0.0.7.jar,\
               lib/jorbis-0.0.15.jar,\
               lib/vorbisspi1.0.2.jar

这里我在lib目录中有3个罐子(这些不是POI罐子,这只是我的一个项目中的一个例子)。

更新MANIFEST.MF并将Bundle-Classpath设置为包含jar。您可以在“Classpath”部分的“运行时”选项卡中的MANIFEST.MF编辑器中执行此操作(使用列表右侧的“添加...”按钮并选择插件中的库)。请务必留下“。”条目。您的MANIFEST.MF最终应该包含一个`Bundle-Classpath'条目,如下所示:

Bundle-ClassPath: .,
 lib/jogg-0.0.7.jar,
 lib/jorbis-0.0.15.jar,
 lib/vorbisspi1.0.2.jar