Load Native Libraries in an Eclipse Rcp Application on Linux

Load native libraries in an Eclipse RCP application on Linux

The most reliable way to find libraries is not using java.library.path at all but finding them via Java code and load via System.load() instead of System.loadLibrary(). You can apply whatever logic you want for finding the native library (although it's probably best trying not to be too clever) and you could fall back to trying java.library.path if your mechanism fails.

This will only work of course if the library doesn't depend on other libraries that might not be found.

How do I tell an Eclipse plugin where a native library resides for an external plugin?

I do something similar in my project.

In my plugin that depends on native code, I have a folder named os at the root of the plugin, with the following contents:

os
-linux
-x86
-<libname>.so
-win32
-x86
-<libname>.dll
-x86_64
-<libname>.dll

the build.properties specifies (among other things) that the os folder should be packaged as part of the plugin build process:

bin.includes = META-INF/,\
plugin.xml,\
lib/,\
os/,\
.,\
schema/

When the product using the plugin runs under one of the platforms for which there is a provided native library, the Java System.loadLibrary("libname") call will resolve the library properly.

This is all being used successfully in my Eclipse 3.6.2 based RCP application. However, I can't find any references that lay out this approach, so I wonder if it's being retired in favor of a more OSGi-friendly approach, using the Bundle-NativeCode directive, which I found several references to:

  • Eclipse Wiki
  • Vogella blog post
  • Blog post

Eclipse Plugin: Order of Native Libraries in the Bundle-NativeCode Section

The order does not matter. Since you have so many libraries. make sure you use ";" to separate them. Using "," will start a new clause that may cause an error if there are not matching attributes on the clause.

Eclipse RCP AspectJ configure

well... this error happened because I haven't reexported the org.aspectj.runtime dependency...

but now I have another error:

!ENTRY org.eclipse.osgi 4 0 2012-03-18 21:33:55.112
!MESSAGE Bundle org.eclipse.equinox.weaving.hook not found.
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.eclipse.equinox.weaving.aspectj.AspectJWeavingActivator.start(Unknown Source)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:389)
at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1130)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438)
at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)
Caused by: java.lang.NoClassDefFoundError: org/eclipse/equinox/service/weaving/IWeavingServiceFactory
at org.eclipse.equinox.weaving.aspectj.AspectJWeavingStarter.start(Unknown Source)
... 20 more
Caused by: java.lang.ClassNotFoundException: org.eclipse.equinox.service.weaving.IWeavingServiceFactory
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:467)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 21 more

I think this is because org.eclipse.equinox.weaving.hook is not found... but I added this -Dosgi.framework.extensions=org.eclipse.equinox.weaving.hook at run configurations.

EDITED with SOLUTION:

found it..

I had to add the aspectj libraries in the same folder where my osgi framework is (where platform is defined)



Related Topics



Leave a reply



Submit