我正在使用 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/