Any package scoped things really should go in the .package file IIRC. 
There is no clever resolving across multiple files (not sure if that is a valid feature request or not). 

On Wed, Dec 15, 2010 at 3:13 AM, Tihomir Surdilovic <tsurdilo@redhat.com> wrote:
Yep, I can reproduce what you are seeing. The order of files being read
in (alphabetical/lexical order..) matters in that the
DroolsCompilerAntTask will compile them one at a time:

public class DroolsCompilerAntTask extends MatchingTask {
....
private void createWithKnowledgeBuilder(AntClassLoader loader) throws
FileNotFoundException,
DroolsParserException,
IOException {
...

for ( int i = 0; i < fileNames.length; i++ ) {
// compile rule file and add to the builder
compileAndAddFile( builder,
fileNames[i] );
}

...
}
}

I'll take a look at the code and fix it up in the near future, but for
now what you can do is just as Mic said to put your declared types in
let's say drools.package file and make sure in your ant tasks that they
get read first. In my simple test this worked fine:

<target name="declaredtypes">
<compiler srcdir="ant" tofile="antout/person.rules">
<!-- classpathref="cheese.classpath" -->
<include name="*.package" />
</compiler>
</target>

<target name="rules" depends="declaredtypes">
<compiler srcdir="ant" tofile="antout/person.rules">
<!-- classpathref="cheese.classpath" -->
<include name="*.drl" />
<include name="*.brl" />
<include name="*.xml" />
<include name="*.dslr" />
</compiler>
</target>

since all declarations are in drools.package (or person.package or
whatever you want to call it), and making sure that "rules" target
depends on the "declaredtypes" target you can assure your declared types
get read first. Let me know if this helps.

Thanks.

On 12/14/10 7:23 AM, stanka wrote:
> Here are more details:
>
> I have one drools resource Person.drl with the following content:
>
> package testpkg
>
> declare Person
>       name : String
> end
>
> And another file PersonRules.drl in the same dir with the following content:
> package testpkg
>
>
> rule "Your First Rule"
>
>       when
>               Person(name == "Bobi")
>       then
>               System.out.println("hi bobi");
>
> end
>
> 1)Drools builder shows an error(Unable to resolve ObjectType person) on line
>               Person(name == "Bobi")
> Is there a way to workarround the problem?
> 2)I construct the knowledgebase using
> http://grepcode.com/file/repository.jboss.com/maven2/org.drools/drools-ant/5.1.0.M1/org/drools/contrib/DroolsCompilerAntTask.java#DroolsCompilerAntTask.execute%28%29
> and  bintype=PACKAGEBINTYPE= "knowledge" and binformat:PACKAGEBINFORMAT !=
> package.
> When I use PeronRules for name of the drools rules resource, the
> knowledgebase is built, but if I rename the file from PeronRules to
> 1PeronRules I get the following error:
> Unable to resolve ObjectType 'Person' : [Rule name='Your First Rule']
>
> The problem with the order is, sometimes the rules filename may be loaded
> after the type declaration which seems to be a problem, how can I deal with
> this?
>

_______________________________________________
rules-dev mailing list
rules-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev



--
Michael D Neale
home: www.michaelneale.net
blog: michaelneale.blogspot.com