8

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:git@github.com:droolsjbpm/drools.git</connection>
    <developerConnection>scm:git:git@github.com:droolsjbpm/drools.git</developerConnection>
    <url>https://github.com/droolsjbpm/drools</url>
  </scm>
</project>
Bhesh Gurung
  • 50,430
  • 22
  • 93
  • 142
Scott Thibault
  • 329
  • 2
  • 4
  • 12
  • 2
    DRL files don't compile to .class files. They are compiled when you create a knowledge base with them. Creating that knowledge base is something that should be happening during your application start-up. – Steve Feb 06 '14 at 09:08
  • 2
    I guess I misspoke, I mean compile to binary form as described in the documentation: The "runtime" requirements mentioned here are if you are deploying rules as their binary form (either as KnowledgePackage objects, or KnowledgeBase objects etc). This is an optional feature that allows you to keep your runtime very light. You may use drools-compiler to produce rule packages "out of process", and then deploy them to a runtime system. This runtime system only requires drools-core.jar and knowledge-api for execution. – Scott Thibault Feb 06 '14 at 15:52
  • So when you build, it's not creating a Jar in the target directory? That's all it's supposed to do. It's not supposed to produce any other kind of output. – Steve Feb 06 '14 at 17:24
  • Yes, I see now that the maven plugin does not do what I was looking for, but how do you do it? Is there a tool to generate serialized KnowledgePackage objects? Or maybe example code for how to build and deploy packages this way? – Scott Thibault Feb 07 '14 at 16:29
  • The jar contains the compiled knowledge package so that you don't need to include drools-compiler on your application classpath. You just include the Jar that it produces as a dependency for your application instead of compiling rules at runtime. I'm a bit puzzled what else you might be trying to do and why you would even want to try to do anything else... – Steve Feb 07 '14 at 16:45
  • There is no knowledge package being generated in my jar file. When I try to run it I get an error: The Eclipse JDT Core jar is not in the classpath – Scott Thibault Feb 07 '14 at 17:18
  • @Scott Thibault I am also trying to use kie-maven-plugin, but couldnt see if the plugin got executed when i run mvn clean install. Is there any other steps that i need to follow. – vashishth Jun 02 '14 at 13:02
  • How you can say it compile the rule artifacts. Can you see this plugin running in maven logs. I tried the same and i coudnt find any logs for this in maven compilation logs. – vashishth Jun 11 '14 at 05:40

3 Answers3

7

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.

Edson Tirelli
  • 3,891
  • 20
  • 23
  • 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. – Sid Datta Nov 13 '14 at 01:21
  • 1
    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. – Edson Tirelli Nov 14 '14 at 23:49
  • @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 (http://www.inf.usi.ch/phd/wettel/codecity.html). A brief explanation of my idea could be found here: https://www.linkedin.com/grp/post/1790946-113334735 – Jackson Cassimiro May 14 '15 at 05:21
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.

Serge
  • 111
  • 2
  • 9
0

It's described in Drools documentation. Just for anybody who find this as first post for 'precompile gdst' on google ;-). You have to define generateModel=YES when compiling. On mvn command line -DgenerateModel=YES or in pom.xml inside kie-maven-plugin <configuration> secion with <generateModel>YES</generateModel>

user2428804
  • 667
  • 7
  • 11