我正在使用在 tomcat 中部署的 guvnor.war 和 drools 6.0.0.Beta5。我成功地创建了业务规则。但是当我尝试从独立的 JAVA 应用程序访问这些规则时,我在
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();
}
}