通过mvn集成测试目标运行optaplanner代码的问题

时间:2019-05-23 17:37:34

标签: maven config solver optaplanner

我有一个使用Optaplanner生成计划的应用程序。当我编写一个集成测试并使用mvn Integration-test从终端的命令行调用该测试时,optaplanner会引发异常。异常是由于“在org.optaplanner.core.config.domain.ScanAnnotatedClassesConfig.buildSolutionDescriptor(ScanAnnotatedClassesConfig.java:84)”引起的“ java.lang.IllegalStateException:zip文件已关闭”。

生产代码有效,我的直觉是无法使用此路径找到求解器配置资源:

solverFactoryBase = SolverFactory
                .createFromXmlResource("solver/solverConfig-minDistanceTimeToProcess.xml");

这是异常堆栈跟踪:

java.lang.IllegalStateException: zip file closed
    at java.util.zip.ZipFile.ensureOpen(ZipFile.java:686)
    at java.util.zip.ZipFile.access$200(ZipFile.java:60)
    at java.util.zip.ZipFile$ZipEntryIterator.hasNext(ZipFile.java:508)
    at java.util.zip.ZipFile$ZipEntryIterator.hasMoreElements(ZipFile.java:503)
    at java.util.jar.JarFile$JarEntryIterator.hasNext(JarFile.java:253)
    at java.util.jar.JarFile$JarEntryIterator.hasMoreElements(JarFile.java:262)
    at org.reflections.vfs.ZipDir$1$1.computeNext(ZipDir.java:30)
    at org.reflections.vfs.ZipDir$1$1.computeNext(ZipDir.java:26)
    at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:145)
    at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:140)
    at org.reflections.Reflections.scan(Reflections.java:243)
    at org.reflections.Reflections.scan(Reflections.java:202)
    at org.reflections.Reflections.<init>(Reflections.java:123)
    at org.optaplanner.core.config.domain.ScanAnnotatedClassesConfig.buildSolutionDescriptor(ScanAnnotatedClassesConfig.java:84)
    at org.optaplanner.core.config.solver.SolverConfig.buildSolutionDescriptor(SolverConfig.java:341)
    at org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:251)
    at org.optaplanner.core.impl.solver.AbstractSolverFactory.buildSolver(AbstractSolverFactory.java:61)
    at com.brc.planner.app.UavRoutePlanner.callSolver(UavRoutePlanner.java:190)
    at com.brc.planner.app.UavRoutePlanner.lambda$createReceive$0(UavRoutePlanner.java:138)
    at akka.japi.pf.UnitCaseStatement.apply(CaseStatements.scala:26)
    at akka.japi.pf.UnitCaseStatement.apply(CaseStatements.scala:21)
    at scala.PartialFunction.applyOrElse(PartialFunction.scala:123)
    at scala.PartialFunction.applyOrElse$(PartialFunction.scala:122)
    at akka.japi.pf.UnitCaseStatement.applyOrElse(CaseStatements.scala:21)
    at scala.PartialFunction$OrElse.applyOrElse(PartialFunction.scala:171)
    at akka.actor.Actor.aroundReceive(Actor.scala:517)
    at akka.actor.Actor.aroundReceive$(Actor.scala:515)
    at akka.actor.AbstractActor.aroundReceive(AbstractActor.scala:180)
    at akka.actor.ActorCell.receiveMessage(ActorCell.scala:588)
    at akka.actor.ActorCell.invoke(ActorCell.scala:557)
    at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:258)
    at akka.dispatch.Mailbox.run(Mailbox.scala:225)
    at akka.dispatch.Mailbox.exec(Mailbox.scala:235)
    at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

1 个答案:

答案 0 :(得分:0)

请勿将createFromXmlResource()createFromXmlFile()混淆。

createFromXmlResource()期望一个类路径资源,该资源通常位于一个命名空间(= java程序包)中,例如"/org/foo/barSolverConfig.xml",以避免在受到超级jarred或压缩压缩时出现麻烦。