创建规则引擎drools时出错

问题描述 投票:1回答:1

我打算使用Openllet推理器,就像其他可用的reasoners一样。但是这个推理器只与OWL API 5.X.X发行版兼容。我有一个包含SWRL规则的xxx.owl文件。由于现有的SWRL API与OWL API 5不兼容,因此Ignazio Palmisano已经提出了一个需要更改的分叉存储库,因此它与OWL API 5.X.X发行版兼容。因此,我删除了与SWRL API和drools引擎相关的依赖项。相反,我通过下载'zip'文件在本地构建它们。

现在,将SWRL API和Drools的“.jar”文件加载到intelliJ中的项目中,我收到以下错误:

Exception in thread "main" org.swrlapi.exceptions.SWRLRuleEngineException: Error creating rule engine Drools. Exception: java.lang.NoClassDefFoundError. Message: org/drools/runtime/rule/AgendaFilter
    at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSWRLRuleEngine(DefaultSWRLRuleAndQueryEngineFactory.java:71)
    at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSWRLRuleEngine(DefaultSWRLRuleAndQueryEngineFactory.java:41)
    at org.swrlapi.factory.SWRLAPIFactory.createSWRLRuleEngine(SWRLAPIFactory.java:38)
    at SWRLrules.main(SWRLrules.java:61)

Caused by: java.lang.NoClassDefFoundError: org/drools/runtime/rule/AgendaFilter
    at org.swrlapi.drools.core.DroolsSWRLRuleEngineCreator.create(DroolsSWRLRuleEngineCreator.java:27)
    at org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSWRLRuleEngine(DefaultSWRLRuleAndQueryEngineFactory.java:59)
    ... 3 more

Caused by: java.lang.ClassNotFoundException: org.drools.runtime.rule.AgendaFilter
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 5 more code here

这里我还在pom.xml文件中附加了依赖项:

<dependencies>

    <dependency>
        <groupId>net.sourceforge.owlapi</groupId>
        <artifactId>owlapi-osgidistribution</artifactId>
        <version>5.1.4</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
    </dependency>
    <dependency>
        <groupId>com.github.galigator.openllet</groupId>
        <artifactId>openllet-owlapi</artifactId>
        <version>2.6.3</version>
    </dependency>

</dependencies>

<build>

    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>org.swrlapi.example.SWRLAPIExample</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>java</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <mainClass>org.swrlapi.example.SWRLAPIExample</mainClass>
            </configuration>
        </plugin>

    </plugins>

</build>

P.S:我在本地构建了swrl api和drools引擎,并将jar文件导入到项目中。

owl-api swrl swrlapi
1个回答
2
投票

您不需要从pom文件中删除依赖项(您看到的错误是由手动过程中遗漏的某些jar引起的)。

如果您使用我的swrlapi fork并将版本更改为,例如,2.0.6-SNAPSHOT,则在本地运行

mvn clean install

将在您的本地maven存储库中放置一个2.0.6-SNAPSHOT jar。此时,将您的pom更改为要求swrlapi 2.0.6-SNAPSHOT,您将在应用程序中获得更新版本。

© www.soinside.com 2019 - 2024. All rights reserved.