Sudipta,<br><br> I believe the problem is that you can't import classes from the default package into your rules file, but I'm not sure.<br><br> Try making Message a top level class (not an inner class) and put it in a package (not the default one). Import it in the DRL and you shall be fine.
<br><br> We need a closer look at this before releasing next major final version.<br><br> []s<br> Edson<br><br><br><div><span class="gmail_quote">2007/4/5, Sudipta deb <<a href="mailto:sudipta_hitk@yahoo.co.in">
sudipta_hitk@yahoo.co.in</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Sir,<br><br>I want to run a simple drools example i.e
. HelloWorldExample from command line<br><br style="font-weight: bold;"><span style="font-weight: bold;">My HelloWorldExample.java---></span><br><br><br style="font-style: italic;"><span style="font-style: italic;">import
java.io.InputStreamReader;</span><br style="font-style: italic;"><span style="font-style: italic;">import java.io.Reader;</span><br style="font-style: italic;"><span style="font-style: italic;">import org.drools.RuleBase;
</span><br style="font-style: italic;"><span style="font-style: italic;">import org.drools.RuleBaseFactory;</span><br style="font-style: italic;"><span style="font-style: italic;">import org.drools.WorkingMemory;</span><br style="font-style: italic;">
<span style="font-style: italic;">import org.drools.compiler.PackageBuilder;</span><br style="font-style: italic;"><span style="font-style: italic;">import org.drools.rule.Package;</span><br style="font-style: italic;"><span style="font-style: italic;">
import org.drools.compiler.PackageBuilderConfiguration;</span><br style="font-style: italic;"><span style="font-style: italic;">import org.drools.compiler.*;</span><br style="font-style: italic;"><span style="font-style: italic;">
import java.lang.String;</span><br style="font-style: italic;"><span style="font-style: italic;">import java.io.*;</span><br style="font-style: italic;"><br style="font-style: italic;"><span style="font-style: italic;">/**
</span><br style="font-style: italic;"><span style="font-style: italic;"> * This is a sample file to launch a rule package from a rule source file.</span><br style="font-style: italic;"><span style="font-style: italic;"> */
</span><br style="font-style: italic;"><br style="font-style: italic;"><br style="font-style: italic;"><span style="font-style: italic;">public class HelloWorldExample </span><br style="font-style: italic;"><span style="font-style: italic;">
{</span><br style="font-style: italic;"><br style="font-style: italic;"><span style="font-style: italic;"> public static final void main(final String[] args) </span><br style="font-style: italic;"><span style="font-style: italic;">
{</span><br style="font-style: italic;"><span style="font-style: italic;"> try </span><br style="font-style: italic;"><span style="font-style: italic;"> {</span><br style="font-style: italic;"><br style="font-style: italic;">
<span style="font-style: italic;"> //load up the rulebase</span><br style="font-style: italic;"><span style="font-style: italic;"> final RuleBase ruleBase = loadRules();</span><br style="font-style: italic;">
<span style="font-style: italic;">
final WorkingMemory workingMemory = ruleBase.newWorkingMemory();</span><br style="font-style: italic;"><br style="font-style: italic;"><span style="font-style: italic;"> //go !</span><br style="font-style: italic;">
<span style="font-style: italic;"> final Message message = new Message();</span><br style="font-style: italic;"><span style="font-style: italic;"> message.setMessage( "Hello World " );</span>
<br style="font-style: italic;"><span style="font-style: italic;"> message.setStatus( Message.HELLO );</span><br style="font-style: italic;"><span style="font-style: italic;"> workingMemory.assertObject
( message );</span><br style="font-style: italic;"><span style="font-style: italic;"> workingMemory.fireAllRules();</span><br style="font-style: italic;"><span style="font-style: italic;"> </span><br style="font-style: italic;">
<span style="font-style: italic;"> } </span><br style="font-style: italic;"><span style="font-style: italic;"> catch ( final Throwable t ) </span><br style="font-style: italic;"><span style="font-style: italic;">
{</span><br style="font-style: italic;"><span style="font-style: italic;"> t.printStackTrace();</span><br style="font-style: italic;"><span style="font-style: italic;"> }</span><br style="font-style: italic;">
<span style="font-style: italic;"> }</span><br style="font-style: italic;"><span style="font-style: italic;"> </span><br style="font-style: italic;"><span style="font-style: italic;"> public static RuleBase loadRules()
</span><br style="font-style: italic;"><span style="font-style: italic;"> {</span><br style="font-style: italic;"><span style="font-style: italic;"> RuleBase ruleBase=null;</span><br style="font-style: italic;">
<span style="font-style: italic;"> try </span><br style="font-style: italic;"><span style="font-style: italic;"> {</span><br style="font-style: italic;"><span style="font-style: italic;"> </span><br style="font-style: italic;">
<span style="font-style: italic;"> String [] ruleFiles = new String
[1]; </span><br style="font-style: italic;"><span style="font-style: italic;"> ruleFiles[0] = "HelloWorld.drl";</span><br style="font-style: italic;"><span style="font-style: italic;">
</span><br style="font-style: italic;"><span style="font-style: italic;"> </span><br style="font-style: italic;"><span style="font-style: italic;"> </span><br style="font-style: italic;"><span style="font-style: italic;">
PackageBuilderConfiguration pkgBuilderCfg = new PackageBuilderConfiguration();</span><br style="font-style: italic;"><span style="font-style: italic;">
pkgBuilderCfg.setCompiler(PackageBuilderConfiguration.JANINO);</span><br style="font-style: italic;"><span style="font-style: italic;"> PackageBuilder builder = new PackageBuilder(pkgBuilderCfg);</span><br style="font-style: italic;">
<span style="font-style: italic;"> for( int i = 0, j = ruleFiles.length; i<j; i++ )</span><br style="font-style: italic;"><span style="font-style: italic;"> {</span><br style="font-style: italic;">
<span style="font-style: italic;"> builder.addPackageFromDrl(new InputStreamReader(HelloWorldExample.class.getResourceAsStream( ruleFiles[i] )) ); //HelloWorldExample.class.getResourceAsStream( "HelloWorld.drl
" )</span><br style="font-style: italic;"><span style="font-style: italic;"> //new InputStreamReader(getClass().getResourceAsStream( ruleFiles[i] ) )</span><br style="font-style: italic;"><span style="font-style: italic;">
}</span><br style="font-style: italic;"><span style="font-style: italic;"> </span><br style="font-style: italic;"><span style="font-style: italic;"> final Package pkg = builder.getPackage();
</span><br style="font-style: italic;"><span style="font-style: italic;"> ruleBase = RuleBaseFactory.newRuleBase();</span><br style="font-style: italic;"><span style="font-style: italic;"> ruleBase.addPackage
(pkg);</span><br style="font-style: italic;"><span style="font-style: italic;"> </span><br style="font-style: italic;"><span style="font-style: italic;"> </span><br style="font-style: italic;"><span style="font-style: italic;">
} </span><br style="font-style: italic;"><span style="font-style: italic;"> catch (Exception fe) </span><br style="font-style: italic;"><span style="font-style: italic;"> {</span><br style="font-style: italic;">
<span style="font-style: italic;"> fe.printStackTrace();</span><br style="font-style: italic;"><span style="font-style: italic;"> }</span><br style="font-style: italic;"><span style="font-style: italic;">
return
ruleBase;</span><br style="font-style: italic;"><span style="font-style: italic;"> }</span><br style="font-style: italic;"><br style="font-style: italic;"><span style="font-style: italic;"> /**</span><br style="font-style: italic;">
<span style="font-style: italic;"> * Please note that this is the "low level" rule assembly API.</span><br style="font-style: italic;"><span style="font-style: italic;"> */</span><br style="font-style: italic;">
<span style="font-style: italic;"> private static RuleBase readRule() throws Exception </span><br style="font-style: italic;"><span style="font-style: italic;"> {</span><br style="font-style: italic;"><span style="font-style: italic;">
//read in the source</span><br style="font-style: italic;"><span style="font-style: italic;">
final Reader source = new InputStreamReader( HelloWorldExample.class.getResourceAsStream( "HelloWorld.drl" ) );</span><br style="font-style: italic;"><br style="font-style: italic;"><span style="font-style: italic;">
//optionally read in the DSL (if you are using it).</span><br style="font-style: italic;"><span style="font-style: italic;"> //Reader dsl = new InputStreamReader( DroolsTest.class.getResourceAsStream( "/mylang.dsl" ) );
</span><br style="font-style: italic;"><br style="font-style: italic;"><span style="font-style: italic;"> //Use package builder to build up a rule package.</span><br style="font-style: italic;"><span style="font-style: italic;">
//An alternative lower level class called "DrlParser" can also be used...</span><br style="font-style: italic;"><br style="font-style: italic;"><span style="font-style: italic;"> final PackageBuilder builder = new PackageBuilder();
</span><br style="font-style: italic;"><br style="font-style: italic;"><span style="font-style: italic;"> //this wil parse and compile in one step</span><br style="font-style: italic;"><span style="font-style: italic;">
//NOTE: There are 2 methods here, the one argument one is for normal DRL.</span><br style="font-style: italic;"><span style="font-style: italic;"> builder.addPackageFromDrl( source );</span><br style="font-style: italic;">
<br style="font-style: italic;"><span style="font-style: italic;"> //Use the following instead of above if you are using a DSL:</span><br style="font-style: italic;"><span style="font-style: italic;">
//builder.addPackageFromDrl( source, dsl );</span><br style="font-style: italic;"><br style="font-style: italic;"><span style="font-style: italic;"> //get the compiled package (which is serializable)</span><br style="font-style: italic;">
<span style="font-style: italic;"> final Package pkg = builder.getPackage();</span><br style="font-style: italic;"><br style="font-style: italic;"><span style="font-style: italic;"> //add the package to a rulebase (deploy the rule package).
</span><br style="font-style: italic;"><span style="font-style: italic;"> final RuleBase ruleBase = RuleBaseFactory.newRuleBase();</span><br style="font-style: italic;"><span style="font-style: italic;"> ruleBase.addPackage
( pkg );</span><br style="font-style: italic;"><span style="font-style: italic;"> return ruleBase;</span><br style="font-style: italic;"><span style="font-style: italic;"> }</span><br style="font-style: italic;">
<span style="font-style: italic;"> </span><br style="font-style: italic;"><span style="font-style: italic;"> public static class Message </span><br style="font-style: italic;"><span style="font-style: italic;"> {
</span><br style="font-style: italic;"><span style="font-style: italic;"> public static final int HELLO = 0;</span><br style="font-style: italic;"><span style="font-style: italic;"> public static final int GOODBYE = 1;
</span><br style="font-style: italic;"><br style="font-style: italic;"><span style="font-style: italic;"> private
String message;</span><br style="font-style: italic;"><br style="font-style: italic;"><span style="font-style: italic;"> private int status;</span><br style="font-style: italic;"><br style="font-style: italic;">
<span style="font-style: italic;"> public String getMessage() </span><br style="font-style: italic;"><span style="font-style: italic;"> {</span><br style="font-style: italic;"><span style="font-style: italic;">
return this.message;</span><br style="font-style: italic;"><span style="font-style: italic;"> }</span><br style="font-style: italic;"><br style="font-style: italic;"><span style="font-style: italic;"> public void setMessage(final String message)
</span><br style="font-style: italic;"><span style="font-style: italic;"> {</span><br style="font-style: italic;"><span style="font-style: italic;"> this.message = message;</span><br style="font-style: italic;">
<span style="font-style: italic;"> }</span><br style="font-style: italic;"><br style="font-style: italic;"><span style="font-style: italic;"> public int getStatus() </span><br style="font-style: italic;"><span style="font-style: italic;">
{</span><br style="font-style: italic;"><span style="font-style: italic;"> return this.status;</span><br style="font-style: italic;"><span style="font-style: italic;"> }</span><br style="font-style: italic;">
<br style="font-style: italic;"><span style="font-style: italic;"> public void setStatus(final int status) </span><br style="font-style: italic;"><span style="font-style: italic;"> {</span><br style="font-style: italic;">
<span style="font-style: italic;"> this.status = status;</span><br style="font-style: italic;"><span style="font-style: italic;"> }</span><br style="font-style: italic;"><span style="font-style: italic;">
}</span><br style="font-style: italic;"><span style="font-style: italic;"> </span><br style="font-style: italic;"><br style="font-style: italic;"><span style="font-style: italic;">}</span><br><br><span style="font-weight: bold;">
My HelloWorld.drl--></span><br><span style="font-style: italic;">package drools_test;</span><br style="font-style: italic;"><br style="font-style: italic;"><span style="font-style: italic;">import HelloWorldExample.*;</span>
<br style="font-style: italic;"><br style="font-style: italic;"><span style="font-style: italic;"> </span><br style="font-style: italic;"><span style="font-style: italic;">rule "Hello World"</span><br style="font-style: italic;">
<span style="font-style: italic;"> when</span><br style="font-style: italic;"><span style="font-style: italic;"> m : Message( status == Message.HELLO, message : message )</span><br style="font-style: italic;"><span style="font-style: italic;">
then</span><br style="font-style: italic;"><span style="font-style: italic;"> System.out.println( message ); </span><br style="font-style: italic;"><span style="font-style: italic;"> m.setMessage( "Goodbye cruel world" );
</span><br style="font-style: italic;"><span style="font-style: italic;"> m.setStatus( Message.GOODBYE );</span><br style="font-style: italic;"><span style="font-style: italic;"> modify( m );</span><br style="font-style: italic;">
<span style="font-style: italic;">end</span><br style="font-style: italic;"><br style="font-style: italic;"><span style="font-style: italic;">rule "GoodBye"</span><br style="font-style: italic;"><span style="font-style: italic;">
no-loop true</span><br style="font-style: italic;"><span style="font-style: italic;"> when</span><br style="font-style: italic;"><span style="font-style: italic;"> m : Message( status == Message.GOODBYE, message : message )
</span><br style="font-style: italic;"><span style="font-style: italic;"> then</span><br style="font-style: italic;"><span style="font-style: italic;"> System.out.println( message ); </span><br style="font-style: italic;">
<span style="font-style: italic;"> m.setMessage( message );</span><br style="font-style: italic;"><span style="font-style: italic;">end<br><br></span>Now compilation works absolutely fine but when i am trying to run it some errors are coming
<span style="font-style: italic;"><br><br>Warning: An error occurred compiling a semantic invoker. Errors should have been reported elsewhere.<br>Warning: An error occurred compiling a semantic invoker. Errors should have been reported elsewhere.
<br>org.drools.rule.InvalidRulePackage: Rule Compilation error Class "HelloWorldExample.Message" not found Class "HelloWorldExample.Message" not found Class "java.lang.Object" has no method named "setMessage" Exception:0
<br>Rule
Compilation error Class "HelloWorldExample.Message" not found Class "HelloWorldExample.Message" not found Class "java.lang.Object" has no method named "setMessage" Exception:0<br>
<br> at org.drools.rule.Package.checkValidity(Unknown Source)<br> at org.drools.common.AbstractRuleBase.addPackage(Unknown Source)<br> at HelloWorldExample.loadRules(HelloWorldExample.java:68)<br> at HelloWorldExample.main
(HelloWorldExample.java:29)<br><br></span>I put all the jar files in the classpath. Please help me.<br><br>With regards,<br><span class="sg"><br>Sudipta Deb. (+919831606520)<br>Kolkata,India<span style="font-style: italic;">
<br></span></span><span class="ad"><p>
        
        
                </p><hr size="1">
Here�s a new way to find what you're looking for - <a href="http://us.rd.yahoo.com/mail/in/yanswers/*http://in.answers.yahoo.com/" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Yahoo! Answers
</a> <p></p></span><br>_______________________________________________<br>rules-users mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org
</a><br><a onclick="return top.js.OpenExtLink(window,event,this)" 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><br clear="all"><br>-- <br> Edson Tirelli<br> Software Engineer - JBoss Rules Core Developer<br> Office: +55 11 3124-6000<br> Mobile: +55 11 9218-4151<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">
www.jboss.com</a>