2016-02-11 44 views
1

我使用DroolsCompilerAntTask为Ant构建和构建Drools的无法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的类对象 我认为当我编译规则时,我没有添加类文件以及规则可能会导致这种情况?或者有没有办法告诉蚂蚁规则编译器的类文件是相关的?如果这是问题,我该如何解决它?

回答

0

编译.drl文件与在几个方面编译Java文件类似。最重要的是,.drl中使用的所有类都必须与.drl位于同一个包中,否则它们必须导入。然而,导入仅仅解析名字空间 - 为了获得类的结构,类的.class文件必须是可用的。编译器怎么知道字段引用是什么意思?

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

+0

你能举一个例子吗?我的意思是如何在.rl中包含.class文件或者需要什么 – logger

+0

taskdef中的classpath和classpathref怎么样?如果你使用的是蚂蚁,你需要知道定义东西的属性。 – laune

+0

我问的原因是因为当我将类添加到路径时,我得到了这个错误。 C:\ Users \ John \ workspacetools \ build.xml:65:RuleBaseTask失败:C:\ Users \ John \ workspace \ build(访问被拒绝) – logger