我想让我的OptaPlanner项目在模块路径上运行。
我基于文档中的云平衡演示创建了一个示例存储库(mwkroening/optaplanner-modulepath-example)。
示例项目在类路径上运行良好,但是在尝试使其在模块路径上运行时,我无法解决该问题。你可以在PR #1看到目前为止的进展。
solverConfig.xml中指定的scoreDrl无法加载,但出现以下异常:
Exception in thread "main" java.lang.IllegalArgumentException: The scoreDrl (io/github/mwkroening/optaplannermodulepathexample/cloudBalancingScoreRules.drl) does not exist as a classpath resource in the classLoader (jdk.internal.loader.ClassLoaders$AppClassLoader@7c16905e).
at [email protected]/org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildDroolsScoreDirectorFactory(ScoreDirectorFactoryConfig.java:519)
at [email protected]/org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildScoreDirectorFactory(ScoreDirectorFactoryConfig.java:351)
at [email protected]/org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:255)
at [email protected]/org.optaplanner.core.impl.solver.AbstractSolverFactory.buildSolver(AbstractSolverFactory.java:61)
at io.github.mwkroening.optaplannermodulepathexample/io.github.mwkroening.optaplannermodulepathexample.App.main(App.java:14)
在调用SolverFactory.createFromXmlResource之前我遇到了类似的异常。我对该问题的解决方法是调用:
SolverFactory.createFromXmlInputStream(
App.class.getResourceAsStream("cloudBalancingSolverConfig.xml"));
我查看了PLANNER-883和psiroky/optaplanner-cloudbalancing-jdk9,但我认为在这种情况下使用了类路径资源而不是模块路径上的资源。
我该如何解决这个问题?也许我应该打开一个问题,而不是在这里发布,对吗?
每个SolverFactory.createFrom*(...)
的重载方法都接受一个类加载器:SolverFactory.createFrom*(..., classloader)
。该类加载器不仅用于加载XML资源,还用于加载DRL资源。
所以尝试:
SolverFactory.createFromXmlResource("/.../cloudBalancingSolverConfig.xml",
App.class.getClassLoader())
我还没有测试过这个,但如果它有效,我很乐意看到这个添加到the "jigsaw" section in the manual(公关欢迎:)。