【问题标题】:JPL Can't find dependent libraries of jpl.dllJPL 找不到 jpl.dll 的依赖库
【发布时间】:2013-06-04 08:37:42
【问题描述】:

在我的电脑上安装 SWI-Prolog 后,我继续尝试它的一个例子,发现了它的特别之处:

run:
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Program Files (x86)\swipl\bin\jpl.dll: Can't find dependent libraries
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1807)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1732)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1028)
    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 main.ProjetoPLP.main(ProjetoPLP.java:12)
Java Result: 1

我已经检查过了,在上述文件夹中一个 jpl.dll 文件,所以我不确定这里发生了什么。我已经检查了这个网站和互联网上的旧问题,但都没有提供任何结论性的答案。

有人知道该怎么做吗?

编辑:

这是我尝试运行的代码,以防万一。

package main;
import java.io.*;
import java.util.Hashtable;
import jpl.Query;
import org.apache.commons.io.*;

public class ProjetoPLP
{

    private static void loadJPLDll() {
    try {
        InputStream in = ProjetoPLP.class.getResourceAsStream("/test/resources/jpl.dll");
        File fileOut = new File("jpl.dll");
        OutputStream out = FileUtils.openOutputStream(fileOut);
        IOUtils.copy(in, out);
        in.close();
        out.close();
        System.load(fileOut.getAbsolutePath());// loading goes here
    } catch (Exception e) {
        e.printStackTrace();
    }
}
    public static void
    main(String args[] )
    {

                loadJPLDll();
        String t1 = "consult('family.pl')";
        Query q1 = new Query(t1);

        System.out.println( t1 + " " + (q1.hasSolution() ? "succeeded" : "failed") );

        //--------------------------------------------------

        String t2 = "child_of(joe, ralf)";
        Query q2 = new Query(t2);

        System.out.println( t2 + " is " + (q2.hasSolution() ? "provable" : "not provable") );

        //--------------------------------------------------

        String t3 = "descendent_of(steve, ralf)";
        Query q3 = new Query(t3);

        System.out.println( t3 + " is " +(q3.hasSolution() ? "provable" : "not provable") );

        //--------------------------------------------------

        String t4 = "descendent_of(X, ralf)";
        Query q4 = new Query(t4);

        System.out.println( "first solution of " + t4 + ": X = " + q4.oneSolution().get("X"));

        //--------------------------------------------------

        Hashtable[] ss4 = q4.allSolutions();

        System.out.println( "all solutions of " + t4);
        for ( int i=0 ; i<ss4.length ; i++ ) {
            System.out.println( "X = " + ss4[i].get("X"));
        }

        //--------------------------------------------------

        System.out.println( "each solution of " + t4);
        while ( q4.hasMoreSolutions() ){
            java.util.Hashtable s4 = q4.nextSolution();
            System.out.println( "X = " + s4.get("X"));
        }

        //--------------------------------------------------

        String t5 = "descendent_of(X,Y)";
        Query q5 = new Query(t5);

        System.out.println( "each solution of " + t5 );
        while ( q5.hasMoreSolutions() ){
            java.util.Hashtable s5 = q5.nextSolution();
            System.out.println( "X = " + s5.get("X") + ", Y = " + s5.get("Y"));
        }

    }

}

【问题讨论】:

  • 你有源代码吗?
  • 我在所有示例中都遇到了相同的异常,所以我认为没有必要。我还应该包括它吗?

标签: java exception jpl


【解决方案1】:

仅供参考,如果你有一个罐子,那么它就不起作用了。

 System.load("xxx.dll"); won't work inside the jar file.

它需要一个物理文件。

你可以做的是:

创建一个名为“test.resources”的包并将您的"jpl.dll" 放入其中。

现在在您的主要方法中,您可以将DLL 加载为

private static void loadJPLDll() {
    try {
        InputStream in = YourCLASS.class.getResourceAsStream("/test/resources/jpl.dll");
        File fileOut = new File("jpl.dll");
        OutputStream out = FileUtils.openOutputStream(fileOut);
        IOUtils.copy(in, out);
        in.close();
        out.close();
        System.load(fileOut.getAbsolutePath());// loading goes here
    } catch (Exception e) {
        e.printStackTrace();
    }
}

记住要完成这项工作,您需要 commons-io jar。

【讨论】:

  • 我不明白一件事(或可能更多),为什么要使用'File fileOut = new File(name);'?或者,更好的是,这个名字应该是什么? 'jpl.dll',或者完全是别的什么?
  • 我已经尝试过了,但它似乎对我不起作用,因为我直到收到同样的异常。是的,我确实有 Apache Commons-io。
  • 我已经在原始帖子中添加了我正在尝试做的事情的源代码。在这种情况下,我有点迷失了,因为我过去没有做过这样的事情。
  • 我自己试过了,我想你会结束添加相当多的其他 dll 文件,因为 jpl.dll 依赖于它们。
  • 所以我应该运行一个应用程序来找出 .dll 具有哪些依赖项并将它们手动添加到我的文件夹中?我会调查的...
【解决方案2】:

如果您在该位置安装了 swi-prolog,请更改环境路径设置并添加 C:\Program Files (x86)\swipl\bin。或者,可以如下所示加载 dll 文件。

private static void loadDLL(String location) {
    try {
        File dll = new File(location);
        System.load(dll.getAbsolutePath());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

public static void main(String[] args) {
    //load the dependent dll files
    loadDLL("libwinpthread-1.dll");
    loadDLL("libgcc_s_sjlj-1.dll");
    loadDLL("libgmp-10.dll");
    loadDLL("libswipl.dll");    
    loadDLL("json.dll");
    loadDLL("jpl.dll");

    //your code here
}

如果使用上述代码,您需要为附加的 JPL.jar 文件添加本地库位置。你可以关注How to set the java.library.path from Eclipse

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-31
    • 2013-06-20
    • 2015-08-21
    • 2019-08-05
    • 2014-08-26
    • 2014-05-28
    • 2012-08-18
    相关资源
    最近更新 更多