Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaSerial lib can't be used in Eclipse equinox OSGi plug-in #11

Closed
trigchen opened this issue Mar 12, 2018 · 11 comments

Comments

@trigchen
Copy link

commented Mar 12, 2018

  1. Create a simple Eclipse 3.x RCP application with the wizard of new plug-in project. Name it as app plugin.
  2. Run app plugin and make sure the simple view defined in the plug-in appear.
  3. Create a plug-in project with the wizard of "Plug-in from existing JAR archives", choose JavaSerial-0.7.jar as external JAR. Name this plug-in as JavaSerial-3rd-lib.
  4. Turn to app plugin, open plugin.xml file and add JavaSerial-3rd-lib plugin as required plug-ins.
  5. Open the View.java file in app plugin, replace the return statement of createInitialDataModel() method with: return Arrays.asList(SerialPort.getSerialPorts());
  6. In the Run configurations -> plug-ins tab, check JavaSerial-3rd-lib plug-in, run it.
  7. Errors occured:

org.eclipse.e4.core.di.InjectionException: java.lang.NoClassDefFoundError: com/rm5248/serial/SerialPort
Caused by: java.lang.NoClassDefFoundError: com/rm5248/serial/SerialPort
at javaserialportosgitest.View.createInitialDataModel(View.java:70)
at javaserialportosgitest.View.createPartControl(View.java:57)

  1. create another plug-in project with the wizard of "Plug-in from existing JAR archives", choose jssc-2.8.0.jar (https://github.com/scream3r/java-simple-serial-connector) as external JAR. Name this plug-in as jssc-3rd-lib.
  2. Add jssc-3rd-lib plugin to the required plugins of app plugin project.
  3. Open the View.java file in app plugin, replace the return statement of createInitialDataModel() method with: return Arrays.asList(SerialPortList.getPortNames());
  4. In the Run configurations -> plug-ins tab, checkjssc-3rd-lib plug-in, run it. The available serial ports list in the view and no error occured.
@rm5248

This comment has been minimized.

Copy link
Owner

commented Mar 13, 2018

Interesting. I think I see what is wrong at the moment; I came across this Stackoverflow the other day, and I think that this may be what is going on.

Anyway, I was able to build a new version of the code with that fix, and everything seems to be working fine. The steps to create the RCP application were very helpful; while I wasn't able to get the exact error that you had, I was able to get a similar problem(Null Pointer on loading the native library).

If you could download the latest build and verify that it works, that would be helpful: https://jenkins.rm5248.com/view/JavaSerial/job/JavaSerial/19/

@trigchen

This comment has been minimized.

Copy link
Author

commented Mar 13, 2018

Test new built JavaSerial-0.9-SNAPSHOT.jar, the same errors occured:

org.eclipse.e4.core.di.InjectionException: java.lang.NoClassDefFoundError: com/rm5248/serial/SerialPort
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:422)
at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:330)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:190)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:105)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:74)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:56)
at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java:129)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:992)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:661)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$1.run(PartRenderingEngine.java:546)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:530)
at org.eclipse.e4.ui.workbench.renderers.swt.ElementReferenceRenderer.createWidget(ElementReferenceRenderer.java:70)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:992)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:661)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
at org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.showTab(StackRenderer.java:1276)
at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer.lambda$0(LazyStackRenderer.java:68)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:40)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:233)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:144)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4894)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:212)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:36)
at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:201)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:196)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:52)
at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:60)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
at org.eclipse.e4.ui.model.application.ui.impl.ElementContainerImpl.setSelectedElement(ElementContainerImpl.java:173)
at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer.postProcess(LazyStackRenderer.java:102)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:679)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java:68)
at org.eclipse.e4.ui.workbench.renderers.swt.SashRenderer.processContents(SashRenderer.java:137)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:675)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
at org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer.processContents(SWTPartRenderer.java:68)
at org.eclipse.e4.ui.workbench.renderers.swt.PerspectiveRenderer.processContents(PerspectiveRenderer.java:48)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:675)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
at org.eclipse.e4.ui.workbench.renderers.swt.PerspectiveStackRenderer.showTab(PerspectiveStackRenderer.java:79)
at org.eclipse.e4.ui.workbench.renderers.swt.LazyStackRenderer.lambda$0(LazyStackRenderer.java:68)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:40)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:233)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:144)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4894)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:212)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:36)
at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:201)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:196)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:52)
at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:60)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
at org.eclipse.e4.ui.model.application.ui.advanced.impl.PerspectiveStackImpl.setSelectedElement(PerspectiveStackImpl.java:135)
at org.eclipse.e4.ui.model.application.ui.advanced.impl.PerspectiveStackImpl.setSelectedElement(PerspectiveStackImpl.java:1)
at org.eclipse.ui.internal.WorkbenchPage.setPerspective(WorkbenchPage.java:4147)
at org.eclipse.ui.internal.WorkbenchWindow.setup(WorkbenchWindow.java:744)
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:498)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:1002)
at org.eclipse.e4.core.internal.di.InjectorImpl.internalInject(InjectorImpl.java:136)
at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:92)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.inject(ContextInjectionFactory.java:74)
at org.eclipse.ui.internal.Workbench.createWorkbenchWindow(Workbench.java:1496)
at org.eclipse.ui.internal.Workbench.getActiveWorkbenchWindow(Workbench.java:1470)
at org.eclipse.ui.internal.services.WorkbenchSourceProvider.updateActiveShell(WorkbenchSourceProvider.java:907)
at org.eclipse.ui.internal.services.WorkbenchSourceProvider.getCurrentState(WorkbenchSourceProvider.java:115)
at org.eclipse.ui.internal.services.WorkbenchSourceProvider.lambda$2(WorkbenchSourceProvider.java:668)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)
at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1271)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1085)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1110)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1095)
at org.eclipse.swt.widgets.Decorations.WM_ACTIVATE(Decorations.java:1698)
at org.eclipse.swt.widgets.Shell.WM_ACTIVATE(Shell.java:2278)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4868)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:359)
at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1657)
at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:2200)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:5183)
at org.eclipse.swt.internal.win32.OS.BringWindowToTop(Native Method)
at org.eclipse.swt.widgets.Decorations.bringToTop(Decorations.java:232)
at org.eclipse.swt.widgets.Shell.open(Shell.java:1270)
at org.eclipse.e4.ui.workbench.renderers.swt.WBWRenderer.postProcess(WBWRenderer.java:782)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:679)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:767)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:738)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:732)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:716)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1076)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1039)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:681)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:595)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
at javaserialportosgitest.Application.start(Application.java:18)
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:388)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
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:498)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:656)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:592)
at org.eclipse.equinox.launcher.Main.run(Main.java:1498)
at org.eclipse.equinox.launcher.Main.main(Main.java:1471)
Caused by: java.lang.NoClassDefFoundError: com/rm5248/serial/SerialPort
at javaserialportosgitest.View.createInitialDataModel(View.java:70)
at javaserialportosgitest.View.createPartControl(View.java:57)
at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(CompatibilityPart.java:151)
at org.eclipse.ui.internal.e4.compatibility.CompatibilityView.createPartControl(CompatibilityView.java:147)
at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:355)
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:498)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:1002)
at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:967)
at org.eclipse.e4.core.internal.di.InjectorImpl.internalInject(InjectorImpl.java:136)
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:411)
... 143 more
Caused by: java.lang.ClassNotFoundException: com.rm5248.serial.SerialPort cannot be found by JavaSerialPortOsgiTest_1.0.0.qualifier
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:508)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:419)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:411)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 157 more

@rm5248

This comment has been minimized.

Copy link
Owner

commented Mar 13, 2018

Could you upload a project that has this error so that I can reproduce it? I can't reproduce the classpath issue, but I could reproduce an issue with loading the native library.

@trigchen

This comment has been minimized.

Copy link
Author

commented Mar 13, 2018

@rm5248

This comment has been minimized.

Copy link
Owner

commented Mar 14, 2018

I tried to build the project, but I didn't have any luck getting it to work with Eclipse(Oxygen). I'm not familiar enough to know what to do in order to get it to build properly. I did manage to install a few plugins and lessen the number of errors, but I still wasn't able to build it fully.

Looking at the stack trace though, it seems to be complaining about the class loader - it's not even finding the library it seems. This sounds like a problem with the project setup in Eclipse.

I've attached a similar sample to your that does work for me.
working-serial-RCP.zip

@rm5248

This comment has been minimized.

Copy link
Owner

commented Mar 21, 2018

Were you ever able to solve this? In the absence of new information, I'm going to assume that there was a project setup problem in Eclipse, since that it what the stack trace implies.

A new release will be out shortly, which will fix a loading of the native library problem which I noticed when investigating this issue.

@trigchen

This comment has been minimized.

Copy link
Author

commented Mar 24, 2018

@rm5248

This comment has been minimized.

Copy link
Owner

commented Mar 24, 2018

Are you sure you're importing it properly? If you look at JavaSerialPortOsgiTest\META-INF\MANIFEST.MF, you'll notice the following:

Import-Package: jssc;version="1.0.0"

The project that I posted is slightly different, in that both JSSC and JavaSerial are under Require-Bundle, but both projects are there. The file is app_plugin2\META-INF\MANIFEST.MF

Require-Bundle: org.eclipse.ui,
 jssc-3rd-lib;bundle-version="1.0.0",
 JavaSerial-snapshot-dependency;bundle-version="1.0.0"
@rm5248

This comment has been minimized.

Copy link
Owner

commented Mar 29, 2018

I was finally able to compile the project that you posted. I wasn't setting my eclipse workspace to where I had extracted the files, and it really didn't like that at all.

As I suspected from your stack traces, there are two problems with your project setup, not with the library itself.

  1. The first problem is that the plugin is not in the 'imported packages' of the MANIFEST.MF. To fix this, open up the MANIFEST.MF in Eclipse(JavaSerialPortOsgiTest/META-INF/MANIFEST.MF). On the right side, there is a pane for "Imported Packages". Add com.rm5248.serial version 1.0.0 to this.
  2. The second problem is that the plugin isn't on the classpath when you run the project. Go to your run configurations for the application(Run->Run Configurations). Under the 'Plug-ins' tab, make sure that all of the projects under 'Workspace' are selected. JavaSerial-3rdLib was not selected, and thus was not on the classpath.

The only other thing that I had to fix was to import the package, as the commented-out code did not import the proper package.

@rm5248 rm5248 closed this Mar 29, 2018
@trigchen

This comment has been minimized.

Copy link
Author

commented Mar 29, 2018

@trigchen

This comment has been minimized.

Copy link
Author

commented Mar 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.