如何告诉一个Eclipse插件,一个本机库驻留在外部插件? [英] How do I tell an Eclipse plugin where a native library resides for an external plugin?

查看:123
本文介绍了如何告诉一个Eclipse插件,一个本机库驻留在外部插件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Eclipse插件,它是C ++库的Java包装器。我在Linux上运行,所以包装器提供了一个.jar和一个.so。我从后一个现有的JAR存档创建了一个插件项目。我已经指向了.so在本地库的位置为jar。



我有另一个插件引用这个包装插件。我可以成功地运行一个独立的java应用程序从这个其他插件成功地使用包装插件。使用它的类必须从包装器jar导入java类,并且在从包装库中实例化任何东西之前,我必须调用System.loadLibrary。这意味着我已经正确设置本地库位置,等等。



当我尝试使用同一种操作,但在使用产品定义的OSGi上下文中时,我得到一个java.lang.UnsatisfiedLinkError。如果我编辑产品定义的运行配置,添加$。code> -Djava.library.path =<完整路径到.so> ,我再次可以运行 - 即,库正常运行。



如何将此路径添加到插件配置?我必须从我的Activator类里面的BundleContext创建一个ClassLoader,或者是否有一个插件配置方式来执行此操作?



我以为我有正确的选择我的包装插件的MANIFEST.MF中的.so到运行时类路径的路径,但似乎没有这样做 - 我想这只是为了类路径而不是库路径。想象一下。



任何想法?

解决方案

我在我的项目中做类似的事情



在我的插件中,依赖于本机代码,我在插件的根目录下有一个名为os的文件夹,内容如下:

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

build.properties指定(除其他事项外)os文件夹应该作为插件构建过程的一部分打包:

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

当使用插件的产品运行在一个有一个提供的本地库的平台,Java System.loadLibrary(libname )调用将正确解析库。



这一切都在我基于Eclipse 3.6.2的RCP应用程序中成功使用。但是,我找不到任何引用这个方法的引用,所以我想知道是否退出了更好的OSGi友好的方法,使用Bundle-NativeCode指令,我发现几个引用:




I have an Eclipse plugin that is a Java wrapper for a C++ library. I'm running on Linux so the wrapper provides a .jar and a .so. I've created a plugin project from this latter existing JAR archive. I have pointed to the .so in the native library location for the jar.

I have another plugin that references this wrapper plugin. I can successfully run a standalone java application from this other plugin that utilizes the wrapper plugin successfully. The class that uses it has to import the java class from the wrapper jar and, before instantiating anything from the wrapper library, I have to call System.loadLibrary. This means I've set the native library location correctly, et cetera.

When I try to do the same kind of operation but within an OSGi context using a product definition, I get a java.lang.UnsatisfiedLinkError. If I edit the run configuration for the product definition to add -Djava.library.path=<full path to the .so>, I am again able to run -- i.e., the library functions properly.

How do I add this path to the plugin configuration? Do I have to create a ClassLoader from my BundleContext inside of my Activator class or is there a plugin configuration way to do this?

I thought I had the right thing by add the path to the .so to the Runtime Classpath in the MANIFEST.MF of my wrapper plugin but that doesn't appear to do it -- I guess it is just for the classpath -- not the library path. Imagine that.

Any ideas?

解决方案

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插件,一个本机库驻留在外部插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆