如何通过Ant构建脚本编译.drl文件 [英] How to compile a .drl file through an ant build script

查看:149
本文介绍了如何通过Ant构建脚本编译.drl文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来Drools的。我想知道是否可以使用某种可以在Windows命令行(壳/ CMD)输入的命令编译.drl文件。我通过附带的Drools发行二进制文件看了,但我无法想出一个办法来编译.drl文件。
我感兴趣的是这样一个命令的原因是,我想写一个Ant构建文件,该文件会编译我的Java类和规则,并创建一个罐子。这个罐子应该是自给自足的,即运行在命令行的jar应该运行主程序,它通过在会话的事实造成了这些事实来自动执行操作的规则。

I am new to Drools. I want to know if it is possible to compile a .drl file using some kind of a command that can be entered in the windows command line (shell/cmd). I looked through the binaries that come with the drools distribution but I am unable to figure out a way to compile a .drl file. The reason I am interested in such a command is that I want to write an ant build file which will compile my java classes and rules and create a jar. This jar should be self sufficient, i.e running the jar from the command line should run the main program, which passes facts in the session causing the rules that operate on these facts to automatically be executed.

推荐答案

DroolsCompilerAntTask 曾经是做到这一点的方式。这将需要所有的各种规则文件,并将其编译成一个序列化的文件。它似乎在5.3的一些错误,虽然我目前试图找出。在此期间,在这里是可用于创建基于Drools的可执行的JAR说明性构建文件。如果规则不能被编译的构建就会失败。

The DroolsCompilerAntTask used to be the way to do this. It would take all your various rule files and compile them into a serialized file. It appears to have some bugs in 5.3 though which I am currently trying to work out. In the meantime, here is an illustrative build file that can be used for creating an executable JAR based on Drools. The build will fail if the rules cannot be compiled.

<project name="DroolsProto" default="dist" basedir=".">
  <property name="build.src" location="src"/>
  <property name="build.target" location="target"/>
  <property name="build.dist"  location="dist"/>
  <property name="build.artifact" value="droolsproto"/>
  <property name="one-jar.dist.dir" value="~/Work/Data/Misc/OneJar"/>   
  <property name="one-jar.version" value="0.97"/>
  <property name="one-jar.ant.jar" value="${one-jar.dist.dir}/one-jar-ant-task-${one-jar.version}.jar"/>

  <path id="build.lib.path">
    <fileset dir="${build.src}/lib">
      <include name="**/*.jar"/>
    </fileset>
  </path>

  <taskdef name="one-jar" classname="com.simontuffs.onejar.ant.OneJarTask"
      classpath="${one-jar.ant.jar}" onerror="report"/>

  <taskdef name="droolscompiler" classname="org.drools.contrib.DroolsCompilerAntTask">
    <classpath refid="build.lib.path"/>
  </taskdef> 

  <target name="clean">
    <delete dir="${build.target}"/>
    <delete dir="${build.dist}"/>
  </target>

  <target name="init">
    <tstamp/>
    <mkdir dir="${build.target}"/>
    <mkdir dir="${build.dist}"/>
  </target>

  <target name="compile" depends="init">
    <mkdir dir="${build.target}/classes"/>
    <javac srcdir="${build.src}/main/java" destdir="${build.target}/classes">
      <classpath refid="build.lib.path"/>
      <include name="**/*.java"/>
      <exclude name="**/*Test.java"/>
    </javac>
  </target>

  <target name="verify-rules">
    <droolscompiler srcDir="${build.src}/main/resources" toFile="${build.target}/classes/foo.foo">
      <classpath refid="build.lib.path"/>
    </droolscompiler>
  </target>

  <target name="verify-resources" depends="verify-rules"/>

  <target name="bundle-resources" depends="verify-resources">
    <copy todir="${build.target}/classes">
      <fileset dir="${build.src}/main/resources"/>
    </copy>
  </target>

  <target name="dist" depends="compile, bundle-resources">
    <one-jar destfile="${build.dist}/${build.artifact}.jar">
      <manifest>
        <attribute name="One-Jar-Main-Class" value="org.drools.examples.HelloWorldExample"/>
      </manifest>
      <main>
        <fileset dir="${build.target}/classes"/>
      </main>
      <lib>
        <fileset dir="${build.src}/lib">
          <include name="**/*.jar"/>
        </fileset>
      </lib>
    </one-jar>
  </target>
</project>

请注意,该构建使用单罐的以创建自包含可执行,则不妨用你选择的超级罐™的工具来替代这次。还有一个 DroolsVerifierAntTask 据称可以在你的规则检查逻辑错误(而不是语法的),但我有经验没动手吧。

Note that the build uses One-Jar in order to create the self-contained executable, you may wish to substitute this with your 'Super Jar™' tool of choice. There is also a DroolsVerifierAntTask which allegedly can check logical errors in your rules (as opposed to syntactical ones), but I have no hands on experience with it.

这篇关于如何通过Ant构建脚本编译.drl文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆