简体   繁体   English

连接java和swi prolog

[英]connect between java and swi prolog

I am trying to run swi prolog from java 我试图从java运行swi prolog
I am using eclipse and I have inserted jpl.jar into the project (properties->libraries->add external jar) and when I am trying to run a program (it is a sample of jpl so it should work..) I am getting an error: 我正在使用eclipse,我已经将jpl.jar插入到项目中(properties-> libraries-> add external jar),当我尝试运行程序时(它是jpl的一个示例,所以它应该工作..)我是收到错误:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jpl in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1758)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1045)
    at jpl.JPL.loadNativeLibrary(JPL.java:100)
    at jpl.fli.Prolog.<clinit>(Prolog.java:85)
    at jpl.Query.open(Query.java:286)
    at jpl.Util.textToTerm(Util.java:162)
    at jpl.Query.<init>(Query.java:198)
    at faf.Main.main(Main.java:10) <br>

what am i missing? 我错过了什么?

I had this problem today on Debian, and my solution was similar to Felix Dobslaw's. 我今天在Debian上遇到了这个问题,我的解决方案类似于Felix Dobslaw的。 Because I couldn't find it elsewhere, I'll post how I solved it today. 因为我在其他地方找不到它,我会发布今天我如何解决它。

My SWI-Prolog and JPL were installed via apt-get. 我的SWI-Prolog和JPL是通过apt-get安装的。 Change the path folders accordinly to your environment. 根据您的环境更改路径文件夹。

  • Copy libswipl.so from /usr/lib to usr/lib/swi-prolog/lib/amd64 libswipl.so/usr/lib复制到usr/lib/swi-prolog/lib/amd64

    ( sudo cp <probably-user-lib>/libswipl.so <installation-folder-swi>/lib/<architeture> ) sudo cp <probably-user-lib>/libswipl.so <installation-folder-swi>/lib/<architeture>

  • Add -Djava.library.path="/usr/lib/swi-prolog/lib/amd64" as VM Option -Djava.library.path="/usr/lib/swi-prolog/lib/amd64"为VM选项

    (Project Properties -> Run -> VM Options) (项目属性 - >运行 - > VM选项)

There should be a jpl dll or so, depending on your platform. 根据您的平台,应该有一个jpl dll左右。 You should either make it accessible somewhere in %PATH% or specify its location with -Djava.library.path=<path to jpl.dll> java property. 您应该使其可以在%PATH%中的某个位置访问,或者使用-Djava.library.path=<path to jpl.dll> java属性指定其位置。

Read more about JPL installation 阅读有关JPL安装的更多信息

I had the same problem. 我有同样的问题。 This helped me on Ubuntu: 这对Ubuntu有帮助:

1) Point the native library location of the jpl jar to the folder where you hold your "libswipl.so" (I do that via the "Java Build Path" settings of the project). 1)将jpl jar的本机库位置指向您保存“libswipl.so”的文件夹(我通过项目的“Java Build Path”设置执行此操作)。 For me that is: 对我来说是:

/usr/lib/swipl-6.2.6/lib/x86_64-linux /usr/lib/swipl-6.2.6/lib/x86_64-linux

2) Add the folder where you hold your "libjava.so" to your LD_LIBRARY_PATH variable (I do that in my run configuration under the Environment tab). 2)将保存“libjava.so”的文件夹添加到LD_LIBRARY_PATH变量中(我在环境选项卡下的运行配置中执行此操作)。 For me that is: 对我来说是:

/usr/lib/jvm/java-6-openjdk/jre/lib/amd64 / usr / lib中/ JVM / JAVA -6-的openjdk / JRE / LIB / AMD64

Solution for Eclipse Neon and homebrew: Eclipse Neon和自制软件的解决方案:

brew update
brew install swi-prolog --with-jpl

In your Eclipse Run/Debug-Configuration set as VM-Arg: 在Eclipse Run / Debug-Configuration中设置为VM-Arg:

-Djava.library.path=/usr/local/Cellar/swi-prolog/7.4.2/libexec/lib/swipl-7.4.2/lib/x86_64-darwin16.6.0

Actual path may vary. 实际路径可能有所不同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM