Drools accessing generated java files

久未见 提交于 2019-12-06 13:32:17

问题


I am executing Drools rule through Mockito test. The rule fails at run time reporting the error with a line number of a java file having some long arbitrary name. It seems that Drools generates java files on the fly and injects into JVM. But when I search those files on my disc I don't find any. Is there a way I could store them on my disc?


回答1:


Got the solution:

You can dump the Drools generated java files in two ways.

1) Through command line:

-Ddrools.dump.dir="target/dumpDir"

e.g. I use maven command to execute the rule so it would be

mvn -Ddrools.dump.dir="target/dumpDir" -Dtest=DroolsRuleTest test

2) Through the API

public class FileKnowledgeBaseFactory implements KnowledgeBaseFactory {
    private Log log = LogFactory.getLog(FileKnowledgeBaseFactory.class);

    public KnowledgeBase load(String drlFullFilename) {
        KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
        config.setOption(DumpDirOption.get(new File("target/dumpDir")));

        KnowledgeBuilder knowledgeBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(config);

        ....
        ....
    }
}


来源:https://stackoverflow.com/questions/21762399/drools-accessing-generated-java-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!