Search code examples
javaeclipsejbossoptaplannerdrools-planner

Optaplanner - The benchmarkConfigResource does not exist as a classpath resource in the classLoader


I'm new to OptaPlanner and I'm focusing on benchmarking. I started playing around with the benchmark in Eclipse. I followed the documentation (http://docs.jboss.org/optaplanner/release/6.4.0.Final/optaplanner-docs/html_single/index.html#buildAndRunAPlannerBenchmark), but when trying to run, I got this error:

Exception in thread "main" java.lang.IllegalArgumentException: The benchmarkConfigResource (prova/src/prova/nurseRosteringBenchmarkConfig.xml) does not exist as a classpath resource in the classLoader (sun.misc.Launcher$AppClassLoader@73d16e93).
    at org.optaplanner.benchmark.impl.XStreamXmlPlannerBenchmarkFactory.configure(XStreamXmlPlannerBenchmarkFactory.java:100)
    at org.optaplanner.benchmark.api.PlannerBenchmarkFactory.createFromXmlResource(PlannerBenchmarkFactory.java:45)
    at prova.ClasseJava.main(ClasseJava.java:10)

Maybe I'm doing something wrong in Java (I need to review it), so here is my code:

package prova;

import org.optaplanner.benchmark.api.PlannerBenchmark;
import org.optaplanner.benchmark.api.PlannerBenchmarkFactory;

public class ClasseJava {
    public static void main(String[] args) {
        System.out.println("Ok - Before");
        PlannerBenchmarkFactory plannerBenchmarkFactory = PlannerBenchmarkFactory.createFromXmlResource(
                "prova/src/prova/nurseRosteringBenchmarkConfig.xml");
        System.out.println("Ok - After");
        PlannerBenchmark plannerBenchmark = plannerBenchmarkFactory.buildPlannerBenchmark();
        plannerBenchmark.benchmark();
    }   
}

Info: I've placed the file nurseRosteringBenchmarkConfig.xml in the same ClasseJava's package (prova).

Thank you for a little help.


Solution

  • Classpath resources are like package names and full classnames. Since your packagename is "prova", your classpath resource is "prova/nurseRosteringBenchmarkConfig.xml".

        PlannerBenchmarkFactory plannerBenchmarkFactory = PlannerBenchmarkFactory.createFromXmlResource(
                "prova/nurseRosteringBenchmarkConfig.xml");