简体   繁体   English

jpl库不适用于Java Maven项目

[英]jpl library won't work with java maven project

I have an issue using jpl library within my project. 我在项目中使用jpl库时遇到问题。

The weird thing is that on an old project, that was an ordinary Java application, worked fine with jpl library by following this solution JPL/SWI Prolog configuration failure . 奇怪的是,在一个旧项目(这是一个普通的Java应用程序)上,通过遵循此解决方案JPL / SWI Prolog配置失败 ,可以与jpl库一起正常工作。 The solution mentioned that I had to configure my enviromental variables in order to make the library talk with Java. 该解决方案提到必须配置环境变量才能使库与Java对话。

On the other hand, my new project is a maven project. 另一方面,我的新项目是Maven项目。 First I included the below dependecy of Maven. 首先,我包括以下Maven的依赖。

    <dependency>
        <groupId>jpl</groupId>
        <artifactId>jpl</artifactId>
        <version>7.4.0</version>
        <type>jar</type>
    </dependency>

But I was getting the below exception: 但是我得到了以下异常:

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: org.jpl7.fli.Prolog.current_query()Lorg/jpl7/fli/qid_t; 线程“ AWT-EventQueue-0”中的异常java.lang.UnsatisfiedLinkError:org.jpl7.fli.Prolog.current_query()Lorg / jpl7 / fli / qid_t; at org.jpl7.fli.Prolog.current_query(Native Method) at org.jpl7.Query.close(Query.java:540) at org.jpl7.Util.textToTerm(Util.java:130) at org.jpl7.Query.(Query.java:185) at com.michalistourism.core.PrologHandler.RunGorgias(PrologHandler.java:47) at com.persistence.TourismSession.RunPrologFile(TourismSession.java:281) at com.michalistourism.tourismassistant.ChatBoxPanel.btnDoNowActionPerformed(ChatBoxPanel.java:109) at com.michalistourism.tourismassistant.ChatBoxPanel.access$100(ChatBoxPanel.java:22) at com.michalistourism.tourismassistant.ChatBoxPanel$2.actionPerformed(ChatBoxPanel.java:74) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) 在org.jpl7.fli.Prolog.current_query(本机方法)在org.jpl7.Query.close(Query.java:540)在org.jpl7.Util.textToTerm(Util.java:130)在org.jpl7.Query 。(Query.java:185)在com.michalistourism.core.PrologHandler.RunGorgias(PrologHandler.java:47)在com.persistence.TourismSession.RunPrologFile(TourismSession.java:281)在com.michalistourism.tourismassistant.ChatBoxPanel.btnDoNowActionPerformed (ChatBoxPanel.java:109)在com.michalistourism.tourismassistant.ChatBoxPanel.access $ 100(ChatBoxPanel.java:22)在com.michalistourism.tourismassistant.ChatBoxPanel $ 2.actionPerformed(ChatBoxPanel.java:74)在javax.swing.AbstractButton。 javax.swing.AbstractButton $ Handler.actionPerformed(AbstractButton.java:2348)的fireActionPerformed(AbstractButton.java:2022)javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)的javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel) .java:259),位于javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) at java.awt.Component.processMouseEvent(Component.java:6533) at javax.swing.JComponent.processMouseEvent(JComponent.java:3324) at java.awt.Component.processEvent(Component.java:6298) at java.awt.Container.processEvent(Container.java:2236) at java.awt.Component.dispatchEventImpl(Component.java:4889) at java.awt.Container.dispatchEventImpl(Container.java:2294) at java.awt.Component.dispatchEvent(Component.java:4711) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466) at java.awt.Container.dispatchEventImpl(Container.java:2280) at java.awt.Window.dispatchEventImpl(Window.java:2746) at java.awt.Component.dispatchEvent(Component.java:4711) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.r 在java.awt的java.awt.Component.processEvent(Component.java:6298)在javax.swing.JComponent.processMouseEvent(JComponent.java:3324)在java.awt.Component.processMouseEvent(Component.java:6533) java.awt.Component.dispatchEventImpl(Component.java:4889)的Container.processEvent(Container.java:2236)java.awt.Component.dispatchEvent(Component的java.awt.Container.dispatchEventImpl(Container.java:2294)的.java:4711)at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)在java.awt的java.awt.Component.dispatchEvent(Component.java:4711)在java.awt.Window.dispatchEventImpl(Window.java:2746)处在java.awt.Container.dispatchEventImpl(Container.java:2280) EventQueue.dispatchEventImpl(EventQueue.java:758)(位于java.awt.EventQueue.access)$ 500(EventQueue.java:97)位于java.awt.EventQueue $ 3.run(EventQueue.java:709),位于java.awt.EventQueue $ 3。 [R un(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90) at java.awt.EventQueue$4.run(EventQueue.java:731) at java.awt.EventQueue$4.run(EventQueue.java:729) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(Event 在java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)处的java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain。 java.awt.EventQueue $ 4.run(java:90)(java.awt.EventQueue $ 4.run(EventQueue.java:729)处java.security.AccessController.doPrivileged(Native Method) .security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)在java.awt.EventQueue.dispatchEvent(EventQueue.java:728)在java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)在java.awt。 java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)处的EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)在java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)处在java.awt.EventDispatchThread.pump DispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) DispatchThread.java:93),位于java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

This is a snippet of my code where the above exception is thrown. 这是我的代码的片段,上面的异常被抛出。

    public PrologReaderCollection RunGorgias(List<Context> contexts) { 

    JPL.init();

    String filename = prologFilePath;

    filename = filename.replace('\\', '/');
    String t1 = "consult('" + filename + "')";
    PrologReaderCollection output = new PrologReaderCollection();
    Integer count =1;

    for(Context cont : contexts) {
        Query q1 = new Query(t1);
        //Query q1 = new Query("consult",new Term[] {new Atom(t1)});
        if (q1.hasNext()) {
            String Request = "prove([" + cont.getName().toLowerCase() + "(" + cont.getParameters() + ")],Expl).";
            q1 = new Query(Request);
            while (q1.hasNext()) {
                    Map<String, Term> map = q1.nextSolution();
                    String expl = map.get("Expl").toString();
                    PrologReader pr = new PrologReader("Solution " + count + " for " + cont.getName().toLowerCase() + ":\n"  + expl + "\n\n",cont.getSet(),cont.getName().toLowerCase());
                    output.add(pr);
                    count += 1;

                    if(count > 3) {
                        break;
                    }
            }
        }
        count = 1;
    }

    return output;
}

Then I tried to add a maven dependecy that points to a jpl jar, that I used on my previous Java project, where the jar file is inside projects lib folder. 然后,我尝试添加一个Maven依赖项,该依赖项指向我在以前的Java项目中使用的jpl jar,该jar文件位于project lib文件夹中。

    <dependency>
        <groupId>jpl</groupId>
        <artifactId>jpl</artifactId>
        <version>7.4.0</version>
        <scope>system</scope>
        <systemPath>${basedir}/lib/jpl.jar</systemPath>
    </dependency> 

项目的文件结构

The new exception in this case is the below one: 在这种情况下,新的异常是以下异常:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/jpl7/JPL at com.michalistourism.core.PrologHandler.RunGorgias(PrologHandler.java:37) at com.persistence.TourismSession.RunPrologFile(TourismSession.java:281) at com.michalistourism.tourismassistant.ChatBoxPanel.btnDoNowActionPerformed(ChatBoxPanel.java:109) at com.michalistourism.tourismassistant.ChatBoxPanel.access$100(ChatBoxPanel.java:22) at com.michalistourism.tourismassistant.ChatBoxPanel$2.actionPerformed(ChatBoxPanel.java:74) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) at java.awt.Component.processMouseEvent(Component.java:6533) at javax.swing.JComponen 线程“ AWT-EventQueue-0”中的异常java.lang.NoClassDefFoundError:com.michalistourism.core.PrologHandler.RunGorgias(PrologHandler.java:37)上的org / jpl7 / JPL com.persistence.TourismSession.RunPrologFile(TourismSession.java) :281),在com.michalistourism.tourismassistant.ChatBoxPanel.btnDoNowActionPerformed(ChatBoxPanel.java:109)处,在com.michalistourism.tourismassistant.ChatBoxPanel.access $ 100(ChatBoxPanel.java:22)在com.michalistourism.tourismassist $$。在javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)上的ChatBoxPanel.java:74)在javax.swing.AbstractButton $ Handler.actionPerformed(AbstractButton.java:2348)上的javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java) :402),位于javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259),位于javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252),位于java.awt.Component.processMouseEvent(Component.java: 6533)在javax.swing.JComponen t.processMouseEvent(JComponent.java:3324) at java.awt.Component.processEvent(Component.java:6298) at java.awt.Container.processEvent(Container.java:2236) at java.awt.Component.dispatchEventImpl(Component.java:4889) at java.awt.Container.dispatchEventImpl(Container.java:2294) at java.awt.Component.dispatchEvent(Component.java:4711) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466) at java.awt.Container.dispatchEventImpl(Container.java:2280) at java.awt.Window.dispatchEventImpl(Window.java:2746) at java.awt.Component.dispatchEvent(Component.java:4711) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) t.processMouseEvent(JComponent.java:3324)at java.awt.Component.processEvent(Component.java:6298)at java.awt.Container.processEvent(Container.java:2236)at java.awt.Component.dispatchEventImpl(Component .java:4889)at java.awt.Container.dispatchEventImpl(Container.java:2294)at java.awt.Component.dispatchEvent(Component.java:4711)at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)在java.awt.Container.dispatchEventImpl(Container.java:2280)在java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)在java.awt.Conweighter.dispatchEventImpl(Container.java:2280)在java.awt.LightweightDispatcher。在java.awt.EventQueue.access $ 500($ 500()处的java.awt.Component.dispatchEvent(Component.java:4711)在java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)处的Window.dispatchEventImpl(Window.java:2746) EventQueue.java:97)at java.awt.EventQueue $ 3.run(EventQueue.java:709)at java.awt.EventQueue $ 3.run(EventQueue.java:703)at java.security.AccessController.doPrivileged(本机方法) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90) at java.awt.EventQueue$4.run(EventQueue.java:731) at java.awt.EventQueue$4.run(EventQueue.java:729) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80) at java.awt.EventQueue.dispatchEvent(EventQueue.java:728) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:8 在java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)在java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)在java.awt.EventQueue $ 4.run(EventQueue.java:731)在java.awt.EventQueue $ 4.run(EventQueue.java:729)在java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)在java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)在java.awt。 java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)处的EventQueue.dispatchEvent(EventQueue.java:728)java.awt.EventDispatchThread.pumpEventsForHierarchy(java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)处的EventQueue.dispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) .java:105),位于java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101),位于java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93),位于java.awt.EventDispatchThread.run(EventDispatchThread.java:8) 2) Caused by: java.lang.ClassNotFoundException: org.jpl7.JPL at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 41 more 2)由以下原因引起:java.lang.ClassNotFoundException:java.net.URLClassLoader.findClass(URLClassLoader.java:381)处的org.jpl7.JPL在sun.misc处java.lang.ClassLoader.loadClass(ClassLoader.java:424) .Launcher $ AppClassLoader.loadClass(Launcher.java:331)at java.lang.ClassLoader.loadClass(ClassLoader.java:357)...另外41个

Is there something I can do? 有什么我可以做的吗?

I've managed to find a solution to my problem by referencing with maven the 7.0.1 version of jpl rather than 7.4.0 and it worked! 通过使用maven引用7.0.1版本的jpl而不是7.4.0,我设法找到了解决我问题的方法,并且可以正常工作! Apparently I needed an older version of the library. 显然我需要一个旧版本的库。

<dependency>
     <groupId>jpl</groupId>
     <artifactId>jpl</artifactId>
     <version>7.0.1</version>  
</dependency>

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

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