Does the InputStream return a reference to your file?
_____
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Michael Fuller
Sent: 30 October 2007 16:04
To: rules-users(a)lists.jboss.org
Subject: [rules-users] RE: JavaConsequenceBuilder.build NullPointerException
I have the following code: (note String[] ruleFiles contains only one
string)
public class Engine {
private static RuleBase ruleBase;
public void start(String[] ruleFiles) throws Exception {
PackageBuilderConfiguration cfg = new PackageBuilderConfiguration();
JavaDialectConfiguration javaConf = (JavaDialectConfiguration)
cfg.getDialectConfiguration("java");
javaConf.setCompiler(JavaDialectConfiguration.ECLIPSE);
PackageBuilder builder = new PackageBuilder(cfg);
for (String file : ruleFiles) {
builder.addPackageFromDrl(new
InputStreamReader(ClassLoader.getSystemResourceAsStream(file)));
}
Package pkg = builder.getPackage();
PackageBuilderErrors errors = builder.getErrors();
if (errors.getErrors().length != 0) {
// do something
}
RuleBaseConfiguration conf = new RuleBaseConfiguration();
conf.setAssertBehaviour(RuleBaseConfiguration.AssertBehaviour.EQUALITY);
ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage(pkg);
ruleBase.newStatefulSession(false);
}
}
At the builder.addPackageFromDrl(new
InputStreamReader(ClassLoader.getSystemResourceAsStream(file))); line I'm
getting the following exception:
java.lang.NullPointerException
at
org.drools.rule.builder.dialect.java.JavaConsequenceBuilder.build(JavaConseq
uenceBuilder.java:54)
at
org.drools.rule.builder.RuleBuilder.build(RuleBuilder.java:67)
at
org.drools.compiler.PackageBuilder.addRule(PackageBuilder.java:446)
at
org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:304)
at
org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:167
)
at myPackage.rivoli.service.rules.Engine.start(Engine.java:33)
at
myPackage.rivoli.rules.LeaderKingAndHeirTest.setUp(LeaderKingAndHeirTest.jav
a:26)
at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39
)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl
.java:25)
at
com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
I am using Drools 4.0.3
I have the following jars in my class path:
antlr-runtime-3.0.jar
core-3.2.3.v_686_R32x.jar
drools-compiler-4.0.3.jar
drools-core-4.0.3.jar
mvel14-1.2.10.jar
Any ideas would be helpful. Thanks.
Michael Fuller
"In theory there is no difference between theory and practice. But, in
practice, there is." - Jan L.A. van de Snepscheut