我正在尝试为最初用C ++编写的库加载jar,但也有java的本机绑定。我通过swig做到了,它为我创建了以下文件 -
我感兴趣的文件是librets.jar(在librets目录下面的第三列)。我在java的测试项目中导入它,然后按照文档编写了以下代码:
package test;
import librets.*;
public class Test {
public static void main(String[] args) throws RetsHttpException, RetsReplyException, RetsException {
System.out.println("Hello world!");
RetsSession session = new RetsSession("http://demo.crt.relators.org:6103/rets/login");
}
}
现在当我运行它时,我得到以下运行时异常,我没有任何线索:
Hello world!
Exception in thread "main" java.lang.UnsatisfiedLinkError: librets.libretsJNI.swig_module_init()V
at librets.libretsJNI.swig_module_init(Native Method)
at librets.libretsJNI.<clinit>(libretsJNI.java:787)
at librets.RetsSession.<clinit>(RetsSession.java:225)
at test.Test.main(Test.java:7)
任何帮助可能是什么原因?
答案 0 :(得分:0)
https://www.chilkatsoft.com/java-loadLibrary-MacOSX.asp链接帮我找到了解决方案。我所要做的就是在我的代码中通过.jnilib
添加System.load
文件。
package test;
import librets.*;
public class Test {
static {
try {
System.load("/Users/Rai/Softwares/libRETS/build/swig/java/liblibrets.jnilib");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String[] args) throws RetsHttpException, RetsReplyException, RetsException {
System.out.println("Hello world!");
RetsSession session = new RetsSession("http://demo.crt.relators.org:6103/rets/login");
}
}