3 Replies Latest reply on Sep 5, 2006 12:02 PM by Galo

    JBoss Rules problem (where else to post?)

    Galo Newbie

      Sorry if this is not the appropiate forum but I can't find anything related to JBoss Rules.

      The examples from the livetrails work perfectly on standalone applications, now I'm trying to get an example running on Jboss 4.0.4GA so I created a simple drl file and an EJB that puts some objects in the working memory etc.

      The EJB runs this code below normally, if I debug and inspect the working memory I can see the rules are loaded (see below the code) and asserted objects are saved. But, misteriously, when it executes fireAllRules nothing happens. No errors shown anywhere. Am I missing something?

      PackageBuilder builder = new PackageBuilder();
      builder.addPackageFromDrl(new InputStreamReader(new java.io.FileInputStream("D:\\noc.drl")));
      RuleBase ruleBase = RuleBaseFactory.newRuleBase();
      WorkingMemory workingMemory = ruleBase.newWorkingMemory();
      Iterator it=this.nocs.iterator();
      System.out.println("Now you should see something:");

      #created on: 31-Aug-2006
      package tal.noc.rules
      import tal.noc.entity.*;
      #list any import classes here.
      #declare any global variables here
      rule "NOC Id >= than 1"
       noc : NOC(id>=1);
       System.out.println("Found with id eq/over 1");
      rule "NOC Id < than 1"
       noc : NOC(id<1);
       System.out.println("Found with id below 1");

      Another question, where should my .drl files be packaged for deployment?


        • 1. Re: JBoss Rules problem (where else to post?)
          Pete Muir Master

          I can't help you with your problem (have you tried the mailing list linked off http://labs.jboss.com?)


          have you looked at Seam's Drools support? It allows you to inject the working memory object and not have to load the rules file from disk.

          • 2. Re: JBoss Rules problem (where else to post?)
            David G. Newbie

            You shouldn't use an absolute path to load your rules.
            Instead, use this method (extracted from Drools examples and modified).

            public static RuleBase readRule(Class readerClass, String rulesFile, String rulesDslFile) throws Exception
             if (rulesFile == null)
             return null;
             PackageBuilder builder = new PackageBuilder();
             Reader source = new InputStreamReader(readerClass.getResourceAsStream(rulesFile));
             if (rulesDslFile == null)
             Reader dsl = new InputStreamReader(readerClass.getResourceAsStream(rulesDslFile));
             builder.addPackageFromDrl(source, dsl);
             RuleBase ruleBase = RuleBaseFactory.newRuleBase();
             Package pkg = builder.getPackage();
             return ruleBase;

            RuleBase ruleBase = readRule(MyClass.class, "rules.drl", null);
            WorkingMemory wm = ruleBase.newWorkingMemory();

            Hope it helps.

            • 3. Re: JBoss Rules problem (where else to post?)
              Galo Newbie

              Thanks for your replies.

              Petemuir, I know there's some support for rules on Seam but I need to stay away from Seam by now.. shame.

              dgallego, thanks, I'll copy that. The .drl file will be then packaged in my .jar file? (something like..)

              | |_ ejb classes
              |_ myrules.drl