java - Drools 在 ant 构建期间无法解析 ObjectType

标签 java ant build drools

我正在使用 DroolsCompilerAntTask 进行 ant 构建,并且在构建过程中收到以下错误

rules:
 [compiler] Unable to resolve ObjectType 'Result' : [Rule name='Test']

对于我有的规则文件

package rules

import com.drools.info.*; 

dialect "java"

rule "Test"   
    when
        $r:Result(total == Result.ONE  )
    then
        System.out.println( "Test Complete." );
end

构建.xml

<!-- rule -->
 <path id="drools.path" >
    <fileset dir="${basedir}/libs">
        <include name="*.jar"/>
    </fileset>  
    <pathelement location="${basedir}/build/rules" /> <- this is my path to compiled class files. If I exclude this line I got the above error. If I include this line then I got the (Access is denied) error. Either way is errored out. Are there permanent solution to this?

 </path>

 <path id="compile.classpath"> 
 </path>

 <taskdef name="compiler" classname="org.drools.contrib.DroolsCompilerAntTask" classpathref="drools.path" />

  <target name="rules" >
    <compiler
      binformat="package" 
      srcdir="${basedir}/src/rules"
      tofile="${basedir}/build"
      classpathref="compile.classpath" >
      <include name="*.drl" />
      <include name="*.brl" />
      <include name="*.xml" />
      <include name="*.dslr" />
    </compiler>
  </target>

其中 Result 是来自 com.drool.info.Result 的类对象 我认为当我编译规则时,我没有将类文件与规则一起添加可能会导致这种情况?或者有没有办法告诉 ant 规则编译器与类文件相关?如果这是问题,我该如何解决它?

最佳答案

编译 .drl 文件在几个方面与编译 Java 文件类似。最重要的是,.drl 中使用的所有类必须与 .drl 位于同一包中,或者必须导入它们。然而,导入仅解析 namespace - 要获取类的结构,该类的 .class 文件必须可用。否则编译器怎么知道字段引用的含义?

确保 .class 文件或包含它们的 .jar 文件位于类路径中。

关于java - Drools 在 ant 构建期间无法解析 ObjectType,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35347105/

相关文章:

java - Java 8 和 JUnit 5 的 Maven 构建失败

java - 在 Java 中什么是嵌套类,它们有什么作用?

java - issueCommand(java.lang.String,int) 在 com.sun.mail.smtp.SMTPTransport 编译错误中具有私有(private)访问权限

java - 如何测试 .class 文件是否已创建?

java - 运行 ant build 得到 "package org.junit does not exist"

Gradle 复制任务 : Ant to gradle migration

java - Ivy 依赖项(拉入文件目录)

go - 如何在主 Go 应用程序中构建新的 Golang 控制台应用程序?

java - Activity 生命周期的方法规则

java - 如何使MpChart的BarChart中的条形图独立且不相关?