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

前端 未结 6 2116
南旧
南旧 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:45

    I faced a similar issue while trying out the JBoss Examples at: 4.2.6.1. Default KieSession http://docs.jboss.org/drools/release/6.4.0.Final/drools-docs/html/ch04.html#KIEExamplesSection

    I was getting the following exception on trying out the default KieSession example:

    org.drools.compiler.kie.builder.impl.ClasspathKieProject - Unable to build index of kmodule.xml url=file:/C:/Repo/Git/temp/drools-examples/drools-examples/drools-examples-service/target/classes/META-INF/kmodule.xml
    org.xml.sax.SAXParseException; systemId: file:/C:/Repo/Git/temp/drools-examples/drools-examples/drools-examples-service/target/classes/META-INF/kmodule.xml; lineNumber: 1; columnNumber: 52; cvc-elt.1.a: Cannot find the declaration of element 'kmodule'.
    10:29:18.243 [main] ERROR org.drools.compiler.kie.builder.impl.KieContainerImpl - Unknown KieSession name: testsession
    

    I realised that the issue was due to the xmlns used in the default kiession example from Jboss Docs: From JBoss Docs - HAS ISSUE:

    kmodule xmlns="http://www.drools.org/xsd/kmodule"
    
    </kmodule>
    

    What I used - WORKS WITHOUT ISSUE:

    kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule"
    
    </kmodule>
    
    0 讨论(0)
  • 2020-12-19 12:48

    In my experience I was trying to add the following maven dependency in pom.xml after removing those dependencies. it worked for me.

        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-core</artifactId>
            <version>${runtime.version}</version>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-decisiontables</artifactId>
            <version>${runtime.version}</version>
        </dependency>
    
        <dependency>
            <groupId>org.jbpm</groupId>
            <artifactId>jbpm-test</artifactId>
            <version>${runtime.version}</version>
        </dependency>
    
    0 讨论(0)
  • 2020-12-19 12:49

    Little late on the answer here, but this might help others.

    Check your META-INF/Maven/pom.properties file, and it might contain this:

    groupId=
    artifactId=
    version=
    

    Nothing was defined! Changed it to:

    groupId=com.sample  (package name)
    artifactId=DroolsTest (class name)
    version=0.0.1-SNAPSHOT  
    

    Copy and paste the same data from pom.properties file to pom.xml . Runs fine now.

    0 讨论(0)
  • 2020-12-19 12:54

    I think there is a much simpler answer ... I stumbled upon this just today as I was attempting the very same thing and got it working after following a clue in the discussion lists:

    I was Trying to get Drools to execute from Spring MVC WEB in Pure Maven Project (no added natures of any kind) and ran head first into this problem:

    ERROR KieContainerImpl - Unknown KieSession name: ksession-rules

    Initial RND: (some direction - but no solutions)

    Unknown KieSession name in drools 6.0 (while trying to add drools to existing maven/eclipse project) http://drools.46999.n3.nabble.com/Null-pointer-exception-when-adding-drools-to-existing-project-td4027944.html#a4028011

    Related Problem (... but a big clue):

    WARN ClasspathKieProject - Unable to load pom.properties tried recursing down from/Apache-Tomcat7/webapps/maven-spring-drools/WEB-INF/classes

    SOLUTION:

    As it turns out, creating the directory WEB-INF/classes and placing the files pom.properties and pom.xml in it solves the problem. The clue came from this link: http://drools.46999.n3.nabble.com/Drools-6-Unable-to-build-index-of-kmodule-xml-td4026791.html - where Mark Proctor indicated that the project has to be a maven project, and it needs to find pom.properties.

    As soon as the KIE finds the pom.properties file, it figures out the KieSession name and the problem is solved.

    Note: I'd suspect you'd have to manually keep that POM.XML file updated but the pom.properties file never changes.

    This has been my experience - hope it helps someone....

    0 讨论(0)
  • 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

     <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
      </plugin>
    

    And

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <version>1.7.2</version>
      <scope>runtime</scope>
    </dependency>
    

    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.

    <?xml version="1.0" encoding="UTF-8"?>
    <kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
        <kbase name="rules" packages="rules">
            <ksession name="ksession-rules"/>
        </kbase>
    </kmodule>
    

    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.

    0 讨论(0)
  • 2020-12-19 12:57

    We have a number of examples, all documented. that get you started. Each can be run from the command line with maven, and have unit test to show them running. https://github.com/droolsjbpm/drools/tree/master/drools-examples-api

    Docs here: http://docs.jboss.org/drools/release/6.0.1.Final/drools-docs/html/KIEChapter.html#KIEExamplesSection

    0 讨论(0)
提交回复
热议问题