Hi, if you write a file in a source folder, it doesn't mean you can immediately access it through the classLoader...Eclipse will put your resource in the classpath when it refreshes the project (e.g. the next time you start the application). This is why you don't get the resource immediately.<div>
If you need that kind of flexibility (write and read a file on the same Thread), you should write on a temporary dir of your project and read from there. To do a better job, i suggest the process of creating the .drl from the .brl should be separated (e.g. compile-time, when you build your project, with maven or ant) . That way, you will always have access to the .drl thtough the class loader.</div>
<div><br></div><div>Regards.<br><div><br><div class="gmail_quote">2010/6/15 Fnu Mahalakshmi <span dir="ltr"><<a href="mailto:FMahalakshmi@nyx.com">FMahalakshmi@nyx.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div lang="EN-US" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial">Hi,</span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial"> </span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial">When I run my project – I have brl and drl rule files.</span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial">When I run it for the first time: I am converting brl to drl
files.</span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial">I get this error</span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""> </span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="red" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:red">Exception in thread "main" </span></font><u><font size="2" color="navy" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:navy">java.lang.NullPointerException</span></font></u><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="red" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:red"> at
java.io.Reader.<init>(Unknown Source)</span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="red" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:red"> at java.io.InputStreamReader.<init>(Unknown
Source)</span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="red" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:red"> at com.org.RuleRunner.loadRuleFile(</span></font><u><font size="2" color="navy" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:navy">RuleRunner.java:87</span></font></u><font size="2" color="red" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:red">) </span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="red" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:red"> at com.org.RuleRunner.loadRules(</span></font><u><font size="2" color="navy" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:navy">RuleRunner.java:44</span></font></u><font size="2" color="red" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:red">)</span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="red" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:red"> at
com.org.RuleRunner.runStatelessRules(</span></font><u><font size="2" color="navy" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:navy">RuleRunner.java:108</span></font></u><font size="2" color="red" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:red">)</span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="red" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:red"> at com.org.RulesTest.main(</span></font><u><font size="2" color="navy" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:navy">RulesTest.java:40</span></font></u><font size="2" color="red" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:red">)</span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial"> </span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial"> </span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial">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.</span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial"> </span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial">So number of .brl files that many number of exceptions(same
as above) and then program runs.</span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial"> </span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial">Why is this happening?? Should it not create the file and load
it into the rulebase?</span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial"> </span></font></p>
<p class="MsoNormal"><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial">My code for converting from brl to drl is :</span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black"> </span></font><b><font size="2" color="#7f0055" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:#7F0055;font-weight:bold">try</span></font></b><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">{</span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">
BRXMLPersistence read = (BRXMLPersistence)
BRXMLPersistence.<i><span style="font-style:italic">getInstance</span></i>();</span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">
BRDRLPersistence write = (BRDRLPersistence)
BRDRLPersistence.<i><span style="font-style:italic">getInstance</span></i>();</span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">
brl = FileUtils.<i><span style="font-style:italic">readFileToString</span></i>(file);
</span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">
System.</span></font><i><font size="2" color="#0000c0" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:#0000C0;font-style:italic">out</span></font></i><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">.println(</span></font><font size="2" color="#2a00ff" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:#2A00FF">"File content: "</span></font><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black"> + brl); </span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">
outputDRL = write.marshal(read.unmarshal(brl));</span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">
String drlFilePath = </span></font><font size="2" color="#2a00ff" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:#2A00FF">"src/main/rules"</span></font><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">+rulesFiles +</span></font><font size="2" color="#2a00ff" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:#2A00FF">".drl"</span></font><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">;</span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">
System.</span></font><i><font size="2" color="#0000c0" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:#0000C0;font-style:italic">out</span></font></i><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">.println(</span></font><font size="2" color="#2a00ff" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:#2A00FF">"drlFilePath "</span></font><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">+drlFilePath +</span></font><font size="2" color="#2a00ff" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:#2A00FF">"rulesFiles "</span></font><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">+rulesFiles);</span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">
String path = rulesFiles+</span></font><font size="2" color="#2a00ff" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:#2A00FF">".drl"</span></font><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">;</span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">
System.</span></font><i><font size="2" color="#0000c0" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:#0000C0;font-style:italic">out</span></font></i><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">.println(</span></font><font size="2" color="#2a00ff" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:#2A00FF">"path "</span></font><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">+path);</span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">
System.</span></font><i><font size="2" color="#0000c0" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:#0000C0;font-style:italic">out</span></font></i><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">.println(</span></font><font size="2" color="#2a00ff" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:#2A00FF">"drlfile "</span></font><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">+drlFilePath);</span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">
drlFile = </span></font><b><font size="2" color="#7f0055" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:#7F0055;font-weight:bold">new</span></font></b><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">
File(drlFilePath);</span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">
FileUtils.<i><span style="font-style:italic">writeStringToFile</span></i>(drlFile,
outputDRL);</span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""> </span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">
Reader source = </span></font><b><font size="2" color="#7f0055" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:#7F0055;font-weight:bold">new</span></font></b><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">
InputStreamReader( RuleRunner.</span></font><b><font size="2" color="#7f0055" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:#7F0055;font-weight:bold">class</span></font></b><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">.getResourceAsStream(path) ); // error is here</span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">
addRulesToThisPackage.addPackageFromDrl(source);</span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">
}</span></font><b><font size="2" color="#7f0055" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:#7F0055;font-weight:bold">catch</span></font></b><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black"> (IOException e)
{</span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""> </span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">
e.printStackTrace(); </span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal" style="text-autospace:none"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">
} </span></font><font size="2" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New""></span></font></p>
<p class="MsoNormal"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">
}</span></font></p>
<p class="MsoNormal"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black"> </span></font></p>
<p class="MsoNormal"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">Any idea why
this problem?? Is there some error in my code above????</span></font></p>
<p class="MsoNormal"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black"> </span></font></p>
<p class="MsoNormal"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">Please help.</span></font></p>
<p class="MsoNormal"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">Thank you</span></font></p>
<p class="MsoNormal"><font size="2" color="black" face="Courier New"><span style="font-size:10.0pt;font-family:"Courier New";color:black">M</span></font><font size="2" face="Arial"><span style="font-size:10.0pt;font-family:Arial"></span></font></p>
</div>
<pre></pre>
<p></p><hr size="1"><p></p>
<p><strong><font color="green">Please consider the environment before printing this email.</font></strong></p>
<p><strong>Visit our website at <a href="http://www.nyse.com" target="_blank">http://www.nyse.com</a> <br>
*****************************************************************************
<br>
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.
</strong></p><pre></pre></div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br></div></div>