Deprecated code of drools to version 6.2

為{幸葍}努か 提交于 2019-11-29 12:35:04

You can simplify Laune's code by using the KieHelper class:

KieHelper kieHelper = new KieHelper();         
kieHelper.addResource(ResourceFactory.newInputStreamResource(new FileInputStream( "simple/simple.drl" )), ResourceType.DRL);

Results results = kieHelper.verify();
if( results.hasMessages( Message.Level.ERROR ) ){
    System.out.println( results.getMessages() );
    throw new IllegalStateException( "### errors ###" );
}

StatelessKieSession kieSession = kieHelper.build().newStatelessKieSession();

Hope it helps.

Try this:

KieServices kieServices = KieServices.Factory.get();
KieFileSystem kfs = kieServices.newKieFileSystem();
FileInputStream fis = new FileInputStream( "simple/simple.drl" );
kfs.write( "src/main/resources/simple.drl",
           kieServices.getResources().newInputStreamResource( fis ) );
KieBuilder kieBuilder = kieServices.newKieBuilder( kfs ).buildAll();
Results results = kieBuilder.getResults();
if( results.hasMessages( Message.Level.ERROR ) ){
    System.out.println( results.getMessages() );
    throw new IllegalStateException( "### errors ###" );
}
KieContainer kieContainer =
    kieServices.newKieContainer( kieServices.getRepository().getDefaultReleaseId() );
KieBase kieBase = kieContainer.getKieBase();
StatelessKieSession kieSession =
    kieContainer.newStatelessKieSession();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!