Created
March 9, 2017 02:51
-
-
Save eternnoir/b990fd8ee3a3d9ca8673906be083e0fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); | |
// 這裡我將drl檔案放在 drools/example1.drl 這裡,記得改成你的檔案目錄 | |
kbuilder.add(ResourceFactory.newClassPathResource("drools/example1.drl"), ResourceType.DRL); | |
// 確認載入是否有錯誤 | |
if (kbuilder.hasErrors()) { | |
System.out.println(kbuilder.getErrors().toString()); | |
throw new RuntimeException("Unable to compile \"example1.drl\"."); | |
} | |
// 取得所有Package | |
Collection<KnowledgePackage> pkgs = kbuilder.getKnowledgePackages(); | |
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(); | |
kbase.addKnowledgePackages(pkgs); | |
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); | |
ksession.addEventListener( new DebugAgendaEventListener() ); | |
// Set up Message. | |
Message message = new Message(); | |
message.setMessage("Hello World"); | |
message.setStatus(Message.HELLO); | |
ksession.insert(message); | |
// 跑所有Rule | |
ksession.fireAllRules(); | |
ksession.dispose(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment