我多年来一直在努力解决下面NullPointerException
。有没有我错过的配置?
Caused by: java.lang.NullPointerException
at org.kie.internal.io.ResourceFactory.newByteArrayResource(ResourceFactory.java:66)
at org.drools.compiler.kie.builder.impl.AbstractKieModule.getResource(AbstractKieModule.java:303)
at org.drools.compiler.kie.builder.impl.AbstractKieModule.addResourceToCompiler(AbstractKieModule.java:268)
at org.drools.compiler.kie.builder.impl.AbstractKieModule.addResourceToCompiler(AbstractKieModule.java:263)
at org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:243)
at org.drools.compiler.kie.builder.impl.AbstractKieProject.verify(AbstractKieProject.java:74)
at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildKieProject(KieBuilderImpl.java:353)
at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:265)
at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:209)
以下是我要遵循的步骤,程序在kieBuilder.buildAll()
行失败:
KieServices kieServices = KieServices.Factory.get();
KieResources kieResources = kieServices.getResources();
KieFileSystem kfs = kieServices.newKieFileSystem();
KieRepository kr = kieServices.getRepository();
Resource res = kieResources.newByteArrayResource(drlFile.getBytes()).setResourceType(ResourceType.DRL).setSourcePath("test.drl");
kfs.write(res);
KieBuilder kieBuilder = kieServices.newKieBuilder(kfs,this.getClass().getClassLoader());
kieBuilder.buildAll();
Maven依赖:
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>7.7.0.Final</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>7.7.0.Final</version>
</dependency>
谢谢!请你帮忙。
答案 0 :(得分:1)
我遇到了同样的错误,这是由于某些KieServices尚未初始化。这些服务是从kie.conf属性文件中读取的,并且上述错误是由于未初始化ResourceFactory Service造成的,请添加“ org.kie.api.io.KieResources = org.drools.core.io.impl.ResourceFactoryServiceImpl” 在您的 kie.conf 文件中以初始化此服务。
答案 1 :(得分:0)
我们发现,当您在7.X系列Drools中创建kie.conf时,会出现此问题,例如,在gradle中使用shadowJar任务时,不会合并kie.conf文件。
解决方法是更新shadowJar任务:
apply plugin: 'com.github.johnrengelman.shadow'
shadowJar {
zip64 true
mergeServiceFiles {
path = 'META-INF'
}
}