尝试使用guvnor中的changeset.xml读取规则会导致错误

时间:2012-07-18 06:25:17

标签: drools eclipse-indigo drools-guvnor

我尝试使用以下代码从Guvnor加载包: -

    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("GenderFact.xml"),ResourceType.CHANGE_SET);
    System.out.println("fair trial");
    KnowledgeBuilderErrors errors = kbuilder.getErrors();
    if (errors.size() > 0) {
        for (KnowledgeBuilderError error: errors) {
            System.err.println(error);
        }
        throw new IllegalArgumentException("Could not parse knowledge.");
    }
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
    return kbase;

并且GenderFact.xml的内容是: -

<change-set xmlns="http://drools.org/drools-5.0/change-set"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0/change-set http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/main/resources/change-set-1.0.0.xsd">
<add>
    <resource
        source="http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/MyLastTrial/LATEST/"
        type="PKG" basicAuthentication="disabled" username="admin" password="admin" />
</add>

当我尝试从Eclipse执行此操作时,出现以下错误: -

  

java.lang.RuntimeException:java.io.InvalidClassException:org.drools.rule.MVELDialectRuntimeData;本地类不兼容:stream classdesc serialVersionUID = 5166066541265170937,本地类serialVersionUID = -64624826351992706       at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:705)       at org.drools.compiler.PackageBuilder.addPackageFromChangeSet(PackageBuilder.java:772)       at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:694)       at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:45)       at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:34)       在com.sample.DroolsTest.readKnowledgeBase(DroolsTest.java:43)       在com.sample.DroolsTest.main(DroolsTest.java:26)   引起:java.io.InvalidClassException:org.drools.rule.MVELDialectRuntimeData;本地类不兼容:stream classdesc serialVersionUID = 5166066541265170937,本地类serialVersionUID = -64624826351992706       at java.io.ObjectStreamClass.initNonProxy(Unknown Source)       at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)       at java.io.ObjectInputStream.readClassDesc(Unknown Source)       at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)       at java.io.ObjectInputStream.readObject0(Unknown Source)       at java.io.ObjectInputStream.readObject(Unknown Source)       在java.util.HashMap.readObject(未知来源)       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)       at java.lang.reflect.Method.invoke(Unknown Source)       at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)       at java.io.ObjectInputStream.readSerialData(Unknown Source)       at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)       at java.io.ObjectInputStream.readObject0(Unknown Source)       at java.io.ObjectInputStream.readObject(Unknown Source)       at org.drools.rule.DialectRuntimeRegistry.readExternal(DialectRuntimeRegistry.java:59)       at java.io.ObjectInputStream.readExternalData(Unknown Source)       at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)       at java.io.ObjectInputStream.readObject0(Unknown Source)       at java.io.ObjectInputStream.readObject(Unknown Source)       at org.drools.rule.Package.readExternal(Package.java:208)       at java.io.ObjectInputStream.readExternalData(Unknown Source)       at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)       at java.io.ObjectInputStream.readObject0(Unknown Source)       at java.io.ObjectInputStream.readObject(Unknown Source)       在org.drools.core.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:205)       在org.drools.core.util.DroolsStreamUtils.streamIn(DroolsStreamUtils.java:189)       at org.drools.compiler.PackageBuilder.addPackageFromInputStream(PackageBuilder.java:781)       at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:692)       ......还有6个

前提条件: -

  • 我使用Guvnor 5.3和jboss AS 7.0。
  • 客户端和服务器共享相同的jre7。
  • 在Eclipse Indigo(Service Release 2)中删除运行时5.3

要求解决方法......

1 个答案:

答案 0 :(得分:4)

在java项目中使用的Drools相关jar与GUvnor 5.3中使用的版本不同。 使用Guvnor 5.3中的jar到你的java项目中。 它会解决问题。 :)