Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
java.lang.RuntimeException: Resource does not have neither a source nor a target path. Impossible to add it to the bundle. Please set either the source or target name of the resource before adding it.null
at org.drools.compiler.kie.builder.impl.KieFileSystemImpl.write(KieFileSystemImpl.java:67)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildKieBase(ScoreDirectorFactoryConfig.java:291)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildDroolsScoreDirectorFactory(ScoreDirectorFactoryConfig.java:270)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildScoreDirectorFactory(ScoreDirectorFactoryConfig.java:177)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildScoreDirectorFactory(ScoreDirectorFactoryConfig.java:165)
at org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:144)
at org.optaplanner.core.config.solver.XmlSolverFactory.buildSolver(XmlSolverFactory.java:104)
at org.optaplanner.examples.common.app.SolverPerformanceTest.solve(SolverPerformanceTest.java:86)
at org.optaplanner.examples.common.app.SolverPerformanceTest.runSpeedTest(SolverPerformanceTest.java:70)
at org.optaplanner.examples.common.app.SolverPerformanceTest.runSpeedTest(SolverPerformanceTest.java:65)
at org.optaplanner.examples.cloudbalancing.CloudBalancingPerformanceTest.solveModel_a2_1(CloudBalancingPerformanceTest.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:62)
The code which triggers this:
KieServices kieServices = KieServices.Factory.get();
KieResources kieResources = kieServices.getResources();
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
for (String scoreDrl : scoreDrlList) {
InputStream scoreDrlIn = getClass().getResourceAsStream(scoreDrl);
if (scoreDrlIn == null) {
throw new IllegalArgumentException("The scoreDrl (" + scoreDrl
+ ") does not exist as a classpath resource.");
}
kieFileSystem.write(kieResources.newInputStreamResource(scoreDrlIn, "UTF-8"));
}
KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
kieBuilder.buildAll();
Results results = kieBuilder.getResults();
if (results.hasMessages(Message.Level.ERROR)) {
throw new IllegalStateException("There are errors in the scoreDrl's:\n"
+ results.toString());
} else if (results.hasMessages(Message.Level.WARNING)) {
logger.warn("There are warning in the scoreDrl's:\n"
+ results.toString());
}
KieContainer kieContainer = kieServices.newKieContainer(kieBuilder.getKieModule().getReleaseId());
KieBase kieBase = kieContainer.getKieBase();
// ruleBaseConfiguration.setOption(PhreakOption.ENABLED);
return kieBase;
@ge0ffrey
Copy link
Author

ge0ffrey commented Mar 25, 2013

Next issue

2013-03-25 12:56:22,351 [Thread-0] WARN No files found for KieBase defaultKieBase

java.lang.RuntimeException: Unexpected global [scoreHolder]
at org.drools.core.common.AbstractWorkingMemory.setGlobal(AbstractWorkingMemory.java:515)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.setGlobal(StatefulKnowledgeSessionImpl.java:360)
at org.optaplanner.core.impl.score.director.drools.DroolsScoreDirector.resetKieSession(DroolsScoreDirector.java:74)
at org.optaplanner.core.impl.score.director.drools.DroolsScoreDirector.setWorkingSolution(DroolsScoreDirector.java:65)
at org.optaplanner.core.impl.solver.scope.DefaultSolverScope.setWorkingSolutionFromBestSolution(DefaultSolverScope.java:176)
at org.optaplanner.core.impl.solver.DefaultSolver.solvingStarted(DefaultSolver.java:176)
at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:154)
at org.optaplanner.examples.common.app.SolverPerformanceTest.solve(SolverPerformanceTest.java:88)
at org.optaplanner.examples.common.app.SolverPerformanceTest.runSpeedTest(SolverPerformanceTest.java:70)
at org.optaplanner.examples.common.app.SolverPerformanceTest.runSpeedTest(SolverPerformanceTest.java:65)
at org.optaplanner.examples.cloudbalancing.CloudBalancingPerformanceTest.solveModel_a2_1(CloudBalancingPerformanceTest.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:62)

Latest code:

public KieBase buildKieBase(List<String> scoreDrlList) {
        KieServices kieServices = KieServices.Factory.get();
        KieResources kieResources = kieServices.getResources();
        KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
        for (String scoreDrl : scoreDrlList) {
            InputStream scoreDrlIn = getClass().getResourceAsStream(scoreDrl);
            if (scoreDrlIn == null) {
                throw new IllegalArgumentException("The scoreDrl (" + scoreDrl
                        + ") does not exist as a classpath resource.");
            }
            kieFileSystem.write(scoreDrl, kieResources.newInputStreamResource(scoreDrlIn, "UTF-8"));
        }
        KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
        kieBuilder.buildAll();
        Results results = kieBuilder.getResults();
        if (results.hasMessages(Message.Level.ERROR)) {
            throw new IllegalStateException("There are errors in the scoreDrl's:\n"
                    + results.toString());
        } else if (results.hasMessages(Message.Level.WARNING)) {
            logger.warn("There are warning in the scoreDrl's:\n"
                    + results.toString());
        }
        KieContainer kieContainer = kieServices.newKieContainer(kieBuilder.getKieModule().getReleaseId());
        KieBase kieBase = kieContainer.getKieBase();
        // ruleBaseConfiguration.setOption(PhreakOption.ENABLED);
        return kieBase;
}

@ge0ffrey
Copy link
Author

ge0ffrey commented Mar 25, 2013

Btw, this doesn't work either:
kieFileSystem.write(kieResources.newClassPathResource(scoreDrl, "UTF-8"));

java.lang.RuntimeException: Unable to get LastModified for ClasspathResource
at org.drools.core.io.impl.ClassPathResource.getLastModified(ClassPathResource.java:207)
at org.drools.core.io.impl.ClassPathResource.getInputStream(ClassPathResource.java:144)
at org.drools.compiler.kie.builder.impl.KieFileSystemImpl.write(KieFileSystemImpl.java:57)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildKieBase(ScoreDirectorFactoryConfig.java:294)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildDroolsScoreDirectorFactory(ScoreDirectorFactoryConfig.java:270)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildScoreDirectorFactory(ScoreDirectorFactoryConfig.java:177)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildScoreDirectorFactory(ScoreDirectorFactoryConfig.java:165)
at org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:144)
at org.optaplanner.core.config.solver.XmlSolverFactory.buildSolver(XmlSolverFactory.java:104)
at org.optaplanner.examples.common.app.SolverPerformanceTest.solve(SolverPerformanceTest.java:86)
at org.optaplanner.examples.common.app.SolverPerformanceTest.runSpeedTest(SolverPerformanceTest.java:70)
at org.optaplanner.examples.common.app.SolverPerformanceTest.runSpeedTest(SolverPerformanceTest.java:65)
at org.optaplanner.examples.cloudbalancing.CloudBalancingPerformanceTest.solveModel_a2_1(CloudBalancingPerformanceTest.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:62)
Caused by: java.io.FileNotFoundException: '/org/optaplanner/examples/cloudbalancing/solver/cloudBalancingScoreRules.drl' cannot be opened because it does not exist
at org.drools.core.io.impl.ClassPathResource.getURL(ClassPathResource.java:168)
at org.drools.core.io.impl.ClassPathResource.getLastModified(ClassPathResource.java:180)
... 21 more

        KieServices kieServices = KieServices.Factory.get();
        KieResources kieResources = kieServices.getResources();
        KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
        for (String scoreDrl : scoreDrlList) {
            InputStream scoreDrlIn = getClass().getResourceAsStream(scoreDrl);
            if (scoreDrlIn == null) {
                throw new IllegalArgumentException("The scoreDrl (" + scoreDrl
                        + ") does not exist as a classpath resource.");
            }
            // Use InputStream to gu

// String path = "src/main/resources/kiebullshit/" + scoreDrl;
// kieFileSystem.write(path, kieResources.newInputStreamResource(scoreDrlIn, "UTF-8"));
kieFileSystem.write(kieResources.newClassPathResource(scoreDrl, "UTF-8"));
}
KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
kieBuilder.buildAll();
Results results = kieBuilder.getResults();
if (results.hasMessages(Message.Level.ERROR)) {
throw new IllegalStateException("There are errors in the scoreDrl's:\n"
+ results.toString());
} else if (results.hasMessages(Message.Level.WARNING)) {
logger.warn("There are warning in the scoreDrl's:\n"
+ results.toString());
}
KieContainer kieContainer = kieServices.newKieContainer(kieBuilder.getKieModule().getReleaseId());
KieBase kieBase = kieContainer.getKieBase();
// ruleBaseConfiguration.setOption(PhreakOption.ENABLED);
return kieBase;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment