How do you pre-compile Drools rules?

12,133

Solution 1

There was a bug in 6.0.1.Final that caused the maven plugin to not save the compiled bytecode inside the kjar. It was fixed after, so if you take the 6.0.2-SNAPSHOT (community) version, or the RedHat BRMS 6.0.1.GA (product) version, it will work.

BZ ticket: https://bugzilla.redhat.com/show_bug.cgi?id=1063255

commit that fixes the bug: https://github.com/droolsjbpm/drools/commit/94b9ccf810100c7ec3f8ed186111720ddb2729d3

FYI, when the correct kjar is generated, it contains a kbase.cache file inside the jar for each defined kbase. These cache files contain the compiled bytecode.

Solution 2

It works for me with kie-maven-plugin 6.1.0.Final, but packaging "kjar" should be specified in order to get KIE base cache inside jar file.

Share:
12,133
Scott Thibault
Author by

Scott Thibault

Updated on June 04, 2022

Comments

  • Scott Thibault
    Scott Thibault almost 2 years

    I want to pre-compile my .drl files to .class files so they do not have to be compiled a run time. The documentation makes it sounds like the kie-maven-plugin does this, but it is not generating anything for me. It compiles the rules files but does not output anything. Any suggestions?

    I'm using the mvn package command, and my pom.xml file is below:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <parent>
        <groupId>org.kie</groupId>
        <artifactId>kie-parent-with-dependencies</artifactId>
        <version>6.0.1.Final</version>
        <!-- relativePath causes out-of-date problems on hudson slaves -->
        <!--<relativePath>../droolsjbpm-build-bootstrap/pom.xml</relativePath>-->
      </parent>
    
      <packaging>kjar</packaging>
      <artifactId>default-kiesession</artifactId>
      <name>Drools API examples - Default KieSession</name>
    
      <dependencies>
        <dependency>
          <groupId>org.drools</groupId>
          <artifactId>drools-compiler</artifactId>
        </dependency>
      </dependencies>
    
      <build>
        <plugins>
          <plugin>
            <groupId>org.kie</groupId>
            <artifactId>kie-maven-plugin</artifactId>
            <version>6.0.1.Final</version>
            <extensions>true</extensions>
            <dependencies>
              <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>1.6.1</version>
              </dependency>
          </dependencies>
          </plugin>
        </plugins>
      </build>
    
      <repositories>
        <!-- Bootstrap repository to locate the parent pom when the parent pom has not been build locally. -->
        <repository>
          <id>jboss-public-repository-group</id>
          <name>JBoss Public Repository Group</name>
          <url>http://repository.jboss.org/nexus/content/groups/public/</url>
          <layout>default</layout>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>never</updatePolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>daily</updatePolicy>
          </snapshots>
        </repository>
      </repositories>
    
      <scm>
        <connection>scm:git:[email protected]:droolsjbpm/drools.git</connection>
        <developerConnection>scm:git:[email protected]:droolsjbpm/drools.git</developerConnection>
        <url>https://github.com/droolsjbpm/drools</url>
      </scm>
    </project>
    
  • Sid Datta
    Sid Datta over 9 years
    Is there a way to generate/save the java files for rules too ? Sometimes the errors refer to the rule java files and it will be useful and educational to be able to see them.
  • Edson Tirelli
    Edson Tirelli over 9 years
    You can set the system property: "drools.dump.dir" to point to the root folder where you want the java files to be dumped. Please note that not everything is generated as a java file. A lot is generated straight into bytecode and will not be dumped.
  • Jackson Cassimiro
    Jackson Cassimiro almost 9 years
    @EdsonTirelli, is there a way to compute complexity metrics from these java files? Few years ago I had a idea consisting in show complexity metrics from drools rules in a 3D form, similar to CodeCity (inf.usi.ch/phd/wettel/codecity.html). A brief explanation of my idea could be found here: linkedin.com/grp/post/1790946-113334735