Optaplanner as jar似乎没有读取xml文件

时间:2018-01-15 15:36:14

标签: jar inputstream filereader optaplanner

我是optaplanner的新手 我在iDE工作并创建了一个工作原型,现在想要进行模拟测试。 我创建了一个整个项目的罐子 但是当我用输入文件调用jar时 我得到例外的“Null POinter Exception” 我试过通过两种方式创建了SolverFactory

Trial 1:
        SolverFactory<PocSolution> factory = SolverFactory.createFromXmlResource(SOLVER_CONFIG,this.getClass().getClassLoader());
Trial 2:
        SolverFactory<PocSolution> factory = SolverFactory.createFromXmlReader(new FileReader(SOLVER_CONFIG),this.getClass().getClassLoader());

Exception in thread "main" java.lang.NullPointerException
    at org.kie.internal.io.ResourceFactory.newByteArrayResource(ResourceFactory.java:66)
    at org.drools.compiler.kie.builder.impl.AbstractKieModule.getResource(AbstractKieModule.java:299)
    at org.drools.compiler.kie.builder.impl.AbstractKieModule.addResourceToCompiler(AbstractKieModule.java:264)
    at org.drools.compiler.kie.builder.impl.AbstractKieModule.addResourceToCompiler(AbstractKieModule.java:259)
    at org.drools.compiler.kie.builder.impl.AbstractKieProject.buildKnowledgePackages(AbstractKieProject.java:228)
    at org.drools.compiler.kie.builder.impl.AbstractKieProject.verify(AbstractKieProject.java:74)
    at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildKieProject(KieBuilderImpl.java:251)
    at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:219)
    at org.drools.compiler.kie.builder.impl.KieBuilderImpl.buildAll(KieBuilderImpl.java:177)
    at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildDroolsScoreDirectorFactory(ScoreDirectorFactoryConfig.java:503)
    at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildScoreDirectorFactory(ScoreDirectorFactoryConfig.java:331)
    at org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:220)
    at org.optaplanner.core.impl.solver.AbstractSolverFactory.buildSolver(AbstractSolverFactory.java:57)
    at org.optaplanner.examples.MyPoc.app.Poc.solve(Poc.java:132)
    at org.optaplanner.examples.MyPoc.app.Poc.main(Poc.java:41)

1 个答案:

答案 0 :(得分:1)

您的求解器配置文件正在成功读取。问题似乎在<scoreDirectorFactory>元素内,您可以在其中指定分数DRL。请确保您使用<scoreDrl>元素和 <scoreDrlFile><scoreDrlFile>应该包含本地文件系统路径,而<scoreDrl>用于加载类路径资源(当DRL文件位于JAR内时就是这种情况)。它看起来应该类似于:

<scoreDirectorFactory>
  <scoreDrl>org/myproj/core/solver/myRules.drl</scoreDrl>
</scoreDirectorFactory>