我买了第三方Java库,其中包含一个JAR文件和两个DLL文件.我编写了自己的Java程序来调用第三方JAR文件.现在我的问题是如何将我的所有代码打包成一个包含我所有代码和第三方JAR和DLL的JAR文件?
我知道SWT就是这种情况.在swt.jar包括DLL文件,但我不知道如何做到这一点,以及如何使其正常工作.
可能重复:
如何在JAR中捆绑本机库和JNI库?
我需要在我的jar中包含本机lib(jnotify,但我认为这没关系).我想用NetBeans来做.
我添加Bundle-NativeCode: /lib/jnotify.dll; osname=win32到我的manifest.mf文件并添加jnotify.dll到projektHome\src\lib\文件夹.但遗憾的是NetBeans正在覆盖 manifest.mf文件.
我怎么修好?我是否可以仅使用NetBeans执行此操作?这是Bundle-NativeCode: /lib/jnotify.dll; osname=win32正确的吗?我还听说我应该把dll哈希manifest.mf并签上我的罐子.真的吗?
OSGi找不到我的DLL文件,我似乎无法弄清楚原因.
目前我foo.dll在我的bundle的根目录下有DLL文件(),我也尝试在libs目录中使用它.
有问题的捆绑的清单看起来像这样:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: foobundle
Bundle-SymbolicName: com.foo.bar
Bundle-Version: 1.0.0
Bundle-Vendor: me
Import-Package: com.sun.jna,
com.sun.jna.ptr,
com.sun.jna.win32
Export-Package: com.foo.bar
Bundle-NativeCode: foo.dll;
osname=WindowsXP;
processor=x86
Run Code Online (Sandbox Code Playgroud)
然后在我的JNA界面中执行loadLibrary(根据文档):
public interface MyFooInterface extends com.sun.jna.Library{
static final MyFooInterface INSTANCE = (MyFooInterface)com.sun.jna.Native.loadLibrary("foo", MyFooInterface .class);
// specific interface defs here...
}
Run Code Online (Sandbox Code Playgroud)
然后在另一个类中我尝试使用JNA接口
// ...code
int var = MyFooInterface.INSTANCE.bar();
// ...more code
Run Code Online (Sandbox Code Playgroud)
我通过另一个包(它导出com.sun.jna和上面导入的其他包)提供了JNA,但是也尝试使用此处定义的包打包它(并在这种情况下将其添加到类路径中等).
我也尝试过指定Bundle-NativeCode: /foo.dll.
同样有趣的是,这些是相关的OSGi属性(我使用了它getprop)
org.osgi.framework.os.name=WindowsXP
org.osgi.framework.processor=x86
Run Code Online (Sandbox Code Playgroud)
即使在所有这些(以及我做的每一次试验)之后,我总是会遇到以下错误(并且未显示堆栈跟踪):
java.lang.UnsatisfiedLinkError: Unable to load library 'foo': The specified module could …Run Code Online (Sandbox Code Playgroud) 我在我的安装程序中使用Hyperic SIGAR库作为第三方库.我的安装程序将所有第三个lib文件解压缩到%TEMP%\\ user文件夹.
在英语操作系统上,一切都很好,但当我尝试在西班牙语Os上运行我的安装程序时,我遇到了以下错误:
java库包含sigar.jar:
java.class.path = C:\ DOCUME~1\西班牙语字母\CONFIG~1\Temp\e4j58.tmp_dir\user\sigar.jar
我的安装程序支持WinXP,WIN7 OS.
错误是:
no sigar-x86-winnt.dll in java.library.path
org.hyperic.sigar.SigarException: no sigar-x86-winnt.dll in java.library.path
at org.hyperic.sigar.Sigar.loadLibrary(Sigar.java:172)
at org.hyperic.sigar.Sigar.<clinit>(Sigar.java:100)
at I4jScript_Internal_1.eval(I4jScript_Internal_1.java:23)
at I4jScript_Internal_1.evaluate(I4jScript_Internal_1.java:79)
at com.install4j.runtime.installer.helper.Script.evaluate(Unknown Source)
at com.install4j.runtime.installer.ContextImpl.runScript(Unknown Source)
at com.install4j.runtime.installer.ContextImpl.runScript(Unknown Source)
at com.install4j.runtime.beans.actions.control.RunScriptAction.execute(Unknown Source)
at com.install4j.runtime.beans.actions.SystemInstallOrUninstallAction.install(Unknown Source)
at com.install4j.runtime.installer.InstallerContextImpl.performActionInt(Unknown Source)
at com.install4j.runtime.installer.ContextImpl.performAction(Unknown Source)
at com.install4j.runtime.installer.controller.Controller.executeActions(Unknown Source)
at com.install4j.runtime.installer.controller.Controller.handleCommand(Unknown Source)
at com.install4j.runtime.installer.controller.Controller.handleStartup(Unknown Source)
at com.install4j.runtime.installer.controller.Controller.start(Unknown Source)
at com.install4j.runtime.installer.Installer.main(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown …Run Code Online (Sandbox Code Playgroud) 要将DLL导入Eclipse Java项目,我检查了"java.library.path"
String path = System.getProperty("java.library.path");
System.out.println(path);
Run Code Online (Sandbox Code Playgroud)
其中一个path值等于C:/Windows/System32.所以我救myAPI.dll了C:/Windows/System32.然后我打电话给System.loadLibrary:
System.loadLibrary("myAPI.dll");
Run Code Online (Sandbox Code Playgroud)
并收到错误消息:
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: Expecting an absolute path of the library: myAPI.dll
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我试图将我的DLL文件放在其他提到的目录中path.但每次我得到相同的错误信息.如何解决这个问题呢?