Drools org.kie.internal.agent.KnowledgeAgentFactory.newKnowledgeAgentConfiguration处出现空指针异常
我正在使用部署在tomcat中的guvnor.war和drools 6.0.0.Beta5。我成功地创建了业务规则。但当我试图从独立JAVA应用程序访问这些规则时,我在Drools org.kie.internal.agent.KnowledgeAgentFactory.newKnowledgeAgentConfiguration处出现空指针异常,drools,drools-guvnor,Drools,Drools Guvnor,我正在使用部署在tomcat中的guvnor.war和drools 6.0.0.Beta5。我成功地创建了业务规则。但当我试图从独立JAVA应用程序访问这些规则时,我在 KnowledgeAgentFactory.newKnowledgeAgentConfiguration() 错误堆栈: Exception in thread "main" java.lang.NullPointerException at org.kie.internal.agent.KnowledgeAgentFactor
KnowledgeAgentFactory.newKnowledgeAgentConfiguration() 错误堆栈:
Exception in thread "main" java.lang.NullPointerException
at org.kie.internal.agent.KnowledgeAgentFactory.newKnowledgeAgentConfiguration(KnowledgeAgentFactory.java:128)
at com.guvnor.GuvnorTest.createKnowledgeBase(GuvnorTest.java:48)
at com.guvnor.GuvnorTest.testDroolsWithGuvnor(GuvnorTest.java:33)
at com.guvnor.Test.main(Test.java:12)
ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183): [../../../src/share/back/util.c:820]
代码:
public class GuvnorTest {
@SuppressWarnings("deprecation")
public void testDroolsWithGuvnor() throws Exception {
KnowledgeBase knowledgeBase = createKnowledgeBase();
StatefulKnowledgeSession session = knowledgeBase.newStatefulKnowledgeSession();
try {
Account account = new Account();
account.setBalance(10);
session.insert(account);
session.fireAllRules();
}
finally {
session.dispose();
}
}
@SuppressWarnings("deprecation")
private static KnowledgeBase createKnowledgeBase() {
KnowledgeAgentConfiguration kaconf = KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
kaconf.setProperty( "drools.agent.scanDirectories", "false" );
kaconf.setProperty( MonitorChangesetEventsOption.PROPERTY_NAME,"true");
kaconf.setProperty( ScanDirectoriesOption.PROPERTY_NAME,"true");
kaconf.setProperty( ScanResourcesOption.PROPERTY_NAME,"true");
kaconf.setProperty( NewInstanceOption.PROPERTY_NAME,"true" );
kaconf.setProperty( UseKnowledgeBaseClassloaderOption.PROPERTY_NAME,"false" );
kaconf.setProperty( ValidationTimeoutOption.PROPERTY_NAME,"0" );
KnowledgeAgent kagent = KnowledgeAgentFactory.newKnowledgeAgent( "test agent", kaconf );
URL url =GuvnorTest.class.getClass().getResource("/src/guvnor-jboss.xml");
kagent.applyChangeSet( ResourceFactory.newClassPathResource("guvnor-jboss.xml"));
// kagent.applyChangeSet(ResourceFactory.newUrlResource(url));
return kagent.getKnowledgeBase();
}
}我没有使用上述代码,而是尝试了以下代码,对我来说效果很好: 源代码: 字符串sourceUrl=
”http://localhost:8080/guvnor/rest/packages/com.sample.model/source“
UrlResource resource = (UrlResource) ResourceFactory
.newUrlResource(sourceUrl);
resource.setBasicAuthentication("enable");
resource.setUsername("suraj");
resource.setPassword("suraj");
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
kbuilder.add(resource, ResourceType.DRL);
KnowledgeBase kbase = kbuilder.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;