Unknown KieSession name in drools 6.0 (while trying to add drools to existing maven/eclipse project)

前端 未结 6 2146
南旧
南旧 2020-12-19 12:24

I am trying to adapt drools6.0 for an existing code base (it is maven project under eclipse). I didnt had need to learn drools or maven before (though they were part of my p

6条回答
  •  一向
    一向 (楼主)
    2020-12-19 12:55

    I hit similar problems.

    I think that part of the problem is trying to live in both worlds. The JBoss Drools eclipse plugin world and the maven world.

    I have Eclipse 4.3.1 (Kepler) with various Jboss/Drools plugins installed.

    I took a working eclipse example and made sure I could run it in maven.

    1. Created a demo drools project File->New->Other..->Drools->Drools Project
    2. Ensured you could run the test programs DroolsTest
    3. Converted project to maven project - Configure->Convert To Maven Project (This will create a pom.xml file with many dependencies. These can be prunes)
    4. Removed the Drools Library from the build path - in the project properties Build Path -> Libraries - select Drools Library and click Remove
    5. Disable the Drools builder - in project properties Builders -> uncheck Drools Builder
    6. Comment out dependancy jsr94 from the pom.xml(not retrievable)
    7. Run maven from the command line "mvm clean install".

    This should give you a project that builds and runs entirely from Maven.

    Add to your pom.xml

     
        org.codehaus.mojo
        exec-maven-plugin
        1.2.1
      
    

    And

    
      org.slf4j
      slf4j-simple
      1.7.2
      runtime
    
    

    Try:

    mvn -e exec:java -Dexec.mainClass="com.sample.DroolsTest"

    It should produce:

    
    ...
    [com.sample.DroolsTest.main()] INFO org.drools.compiler.kie.builder.impl.ClasspathKieProject - Found kmodule: file:/Users/davidbernard/Projects/action-deducing-diff/xx/target/classes/META-INF/kmodule.xml
    [com.sample.DroolsTest.main()] INFO org.drools.compiler.kie.builder.impl.KieRepositoryImpl - KieModule was added:FileKieModule[ ReleaseId=x:x:1.0file=/Users/davidbernard/Projects/action-deducing-diff/xx/target/classes]
    [com.sample.DroolsTest.main()] INFO org.drools.compiler.kie.builder.impl.ClasspathKieProject - Found kmodule: file:/Users/davidbernard/Projects/action-deducing-diff/xx/target/classes/META-INF/kmodule.xml
    [com.sample.DroolsTest.main()] INFO org.drools.compiler.kie.builder.impl.KieRepositoryImpl - KieModule was added:FileKieModule[ ReleaseId=x:x:1.0file=/Users/davidbernard/Projects/action-deducing-diff/xx/target/classes]
    Hello World
    Goodbye cruel world
    ...
    
    

    You should now also be able to run DroolsTest from eclipse.

    You will have a rules->Sample.drl file and a kmodule.xml file.

    
    
        
            
        
    
    

    The "ksession" name should match the code creating the ksession:

    KieSession kSession = kContainer.newKieSession("ksession-rules");
    

    The "packages" should match the directory the rule file is in.

提交回复
热议问题