2

I was getting this exception but I am not able to understand what is happening there.

Because on compilation time my class able access apache POI classes but on runtime my classes throws exception that he is not able find

org.apache.poi.xssf.usermodel.XSSFWorkbook.

Till now whatever solution is provided on net I have tried everything but not understanding what I am missing.

And weird thing is same code and same Apache POI library working on my friend's eclipse. We both have identical projects. Don't understand what is going on there.

I checked all folder's access where I am referring libraries.

Please share if you have any suggestion.

I am getting the following exception.

!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 as follow

    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 as follow

source.. = src/
output.. = bin/
bin.includes = META-INF/,\
               .,\
               plugin.xml,\
               icons/,\
               OSGI-INF/l10n/message.properties
9
  • 2
    The POI jar file is missing from your classpath. Commented May 26, 2017 at 4:58
  • In eclipse by using build path i added POI jar. and if there is No POI jar this exception is suggesting then how eclipse allow me to access "XSSFWorkbook" classes. In my code. Because i dont have any compilation errors. Commented May 26, 2017 at 5:03
  • 1
    It's a runtime error, so runtime classpath is wrong and not the build path. See stackoverflow.com/questions/2520821/…. Commented May 26, 2017 at 5:11
  • i created one test project inside same workspace . In that project i added one simple class which are using POI classes. i build same jars from same location but that are running... still you think it is same issue..what you mentioned above. ? Commented May 26, 2017 at 5:49
  • 1
    Is this an Eclipse plugin you are writing? Plugins have special classpath requirements, just setting the build path properties is not correct. Commented May 26, 2017 at 6:43

1 Answer 1

5

A plugin can only access classes in other plugins or in jars included in the plugin which are included in the bundle class path. Setting the Java Build Path properties does not configure the plugin correctly.

Add all the jars you need to the plugin, usually these are put in a 'lib' directory.

Update the build.properties to include these jars in the 'bin.includes' section. For example:

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

Here I have 3 jars in a lib directory (these are not the POI jars, this is just an example from one of my projects).

Update the MANIFEST.MF and set the Bundle-Classpath to include the jars. You can do this in the MANIFEST.MF editor in the 'Runtime' tab in the 'Classpath' section (use the Add... button to the right of the list and choose the libraries in the plugin). Be sure to leave the entry for '.'. Your MANIFEST.MF should end up containing a `Bundle-Classpath' entry like this:

Bundle-ClassPath: .,
 lib/jogg-0.0.7.jar,
 lib/jorbis-0.0.15.jar,
 lib/vorbisspi1.0.2.jar
Sign up to request clarification or add additional context in comments.

4 Comments

thanks for ur time. i did first step. in second step "'Runtime' tab in the 'Classpath' section" how those entries will come there. can i edit directly MANIFEST.MF file manually by writing all library name ?
You click the Add... button to the right of the Classpath list and select the jars in the plugin, or you can edit the MANIFEST.MF directly.
Do you think question title need to change here ? because in future if anyone has this same issue he could save his time.
I think the title is OK

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.