Why are you trying to read it from your classpath? As it wasn't in your classpath
when you loaded java doesn't know about it.
You already have the File object so you can just make a FileReader object from that.
Reader source = new FileReader(drlFile);
Don't forget to close your reader when you are done with it, ideally in a finally
block so that ti gets closed even if there is an IOException while reading from it.
Also you really really really shouldn't write files into your source directory as it
means that running a clean doesn't work properly, is likely to confuse eclipse and
lead to all sorts of other funnies like dynamic files suddenly appearing in your
classpath... For unit tests write it to "target/testOutput" or similar.
Hope this helps,
Thomas
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On
Behalf Of Fnu Mahalakshmi
Sent: 15 June 2010 22:05
To: 'rules-users(a)lists.jboss.org'
Subject: [rules-users] Weird error with rule files
Hi,
When I run my project - I have brl and drl rule files.
When I run it for the first time: I am converting brl to drl files.
I get this error
Exception in thread "main" java.lang.NullPointerException
at java.io.Reader.<init>(Unknown Source)
at java.io.InputStreamReader.<init>(Unknown Source)
at com.org.RuleRunner.loadRuleFile(RuleRunner.java:87)
at com.org.RuleRunner.loadRules(RuleRunner.java:44)
at com.org.RuleRunner.runStatelessRules(RuleRunner.java:108)
at com.org.RulesTest.main(RulesTest.java:40)
But after I run it for the first time and the rule.drl (converted file from brl to drl)
exists in my directory - I run it again and then the program runs fine.
So number of .brl files that many number of exceptions(same as above) and then program
runs.
Why is this happening?? Should it not create the file and load it into the rulebase?
My code for converting from brl to drl is :
try{
BRXMLPersistence read = (BRXMLPersistence)
BRXMLPersistence.getInstance();
BRDRLPersistence write = (BRDRLPersistence)
BRDRLPersistence.getInstance();
brl = FileUtils.readFileToString(file);
System.out.println("File content: " + brl);
outputDRL = write.marshal(read.unmarshal(brl));
String drlFilePath = "src/main/rules"+rulesFiles
+".drl";
System.out.println("drlFilePath "+drlFilePath +"rulesFiles
"+rulesFiles);
String path = rulesFiles+".drl";
System.out.println("path "+path);
System.out.println("drlfile "+drlFilePath);
drlFile = new File(drlFilePath);
FileUtils.writeStringToFile(drlFile, outputDRL);
Reader source = new InputStreamReader(
RuleRunner.class.getResourceAsStream(path) ); // error is here
addRulesToThisPackage.addPackageFromDrl(source);
}catch (IOException e) {
e.printStackTrace();
}
}
Any idea why this problem?? Is there some error in my code above????
Please help.
Thank you
M
________________________________
Please consider the environment before printing this email.
Visit our website at
http://www.nyse.com
*****************************************************************************
Note: The information contained in this message and any attachment to it is privileged,
confidential and protected from disclosure. If the reader of this message is not the
intended recipient, or an employee or agent responsible for delivering this message to the
intended recipient, you are hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited. If you have received this
communication in error, please notify the sender immediately by replying to the message,
and please delete it from your system. Thank you. NYSE Euronext.
________________________________
**************************************************************************************
This message is confidential and intended only for the addressee. If you have received
this message in error, please immediately notify the postmaster(a)nds.com and delete it from
your system as well as any copies. The content of e-mails as well as traffic data may be
monitored by NDS for employment and security purposes. To protect the environment please
do not print this e-mail unless necessary.
NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United
Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603
8808 40-00
**************************************************************************************