Org.drools.rule.invalidrulepackage Global Error
Contents |
java.io.Reader;import org.drools.RuleBase;import org.drools.RuleBaseFactory;import org.drools.WorkingMemory;import org.drools.compiler.PackageBuilder;import org.drools.rule.Package;import org.drools.compiler.PackageBuilderConfiguration;import org.drools.compiler.*;import java.lang.String;import java.io.*;/*** This is a sample file to launch a rule package from a unable to resolve objecttype drools rule source file.*/public class HelloWorldExample { public static final void rule compilation error cannot be resolved to a variable main(final String[] args) { try { //load up the rulebase final RuleBase ruleBase = drools rule compilation error cannot be resolved loadRules(); final WorkingMemory workingMemory = ruleBase.newWorkingMemory(); //go ! final Message message = new Message(); message.setMessage( "Hello World " ); message.setStatus( Message.HELLO ); workingMemory.assertObject( message ); workingMemory.fireAllRules(); drools cannot be resolved to a variable } catch ( final Throwable t ) { t.printStackTrace(); } } public static RuleBase loadRules() { RuleBase ruleBase=null; try { String [] ruleFiles = new String [1]; ruleFiles[0] = "HelloWorld.drl";
Drools Syntax
PackageBuilderConfiguration pkgBuilderCfg = new PackageBuilderConfiguration(); pkgBuilderCfg.setCompiler(PackageBuilderConfiguration.JANINO); PackageBuilder builder = new PackageBuilder(pkgBuilderCfg); for( int i = 0, j = ruleFiles.length; i here for a quick overview of the site Help Center Detailed answers to any questions you might have drools tutorial Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask http://osdir.com/ml/java.drools.user/2007-04/msg00023.html Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up cannot load drools rule, getting error: unable to resolve object type up vote 0 down http://stackoverflow.com/questions/21131880/cannot-load-drools-rule-getting-error-unable-to-resolve-object-type vote favorite i'm new to drools, i'm trying to run the hello world but it keeps giving me this error Some errors exists in packageBuilder Unable to resolve ObjectType 'Messagee' : [Rule name='Hello World'] Exception in thread "main" java.lang.IllegalArgumentException: Could not parse knowledge. at hellodrools.HelloWorldRuleTest.initialiseDrools(HelloWorldRuleTest.java:55) at hellodrools.HelloWorldRuleTest.main(HelloWorldRuleTest.java:26) Rule Compilation error : [Rule name='Hello World'] hellodrools/Message/Rule_Hello_World720710180.java (1:8) : The package hellodrools.Message collides with a type my drl file: package hellodrools.Message rule 'Hello World' when message:Message (type == 'Hello') then message.printMessage(); end Message.java package hellodrools; public class Message{ private String type; public String getType() { return type; } public void setType(String type) { this.type = type; } public void printMessage() { System.out.println("Type: " + type); } } HelloWorldTestRule.java package hellodrools; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.util.logging.Level; import java.util.logging.Logger; import org.drools.core.RuleBase; import org.drools.core.RuleBaseFactory; import org.drools.core.StatefulSession; import org.drools.compiler.compiler.DroolsParserException; import org.drools.compiler.compiler.PackageBuilder; import org.drools.compiler.co threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ http://drools-moved.46999.n3.nabble.com/Rule-Compilation-error-td48401.html Rule Compilation error Can someone help me with this? The rule doesn't have any commas. It calls a "global" objects (navService) boolean methods. If http://www.codeodor.com/index.cfm/2007/9/10/rules-based-programming-with-jboss-rulesdrools/1600 the "eval" is commented out it works. I've used the global object in other more complicated rules and it works fine. rule "Menu cannot be Dependents Not Elig" when menuNavItem : MenuNavItem( id == NavConstants.NAV_DEPENDENTS ) // Can't have Dependents without HW Plans. eval( !navService.haveHWPlans() cannot be resolved ) then System.out.println( "Menu Dependents Not Elig: "+menuNavItem.getId() ); retract( menuNavItem ); end . org.drools.rule.InvalidRulePackage: Rule Compilation error Syntax error on token ",", delete this token at org.drools.rule.Package.checkValidity(Package.java:378) at org.drools.reteoo.RuleBaseImpl.addPackage(RuleBaseImpl.java:303) at org.drools.jsr94.rules.admin.RuleExecutionSetImpl. rules based programming, or a bit of theory, you can skip straight the Drools tutorial. Background One of the concepts I love to think about (and do) is raising the level of abstraction in a system. The more often you are telling the computer what, and not how, the better. Of course, somewhere someone is doing imperative programming (telling it how), but I like to try to hide much of that somewhere and focus more on declarative programming (telling it what). Many times, that's the result of abstraction in general and DSLs and rules-based programming more specifically. As a side note, let me say that this is not necessarily a zero-sum game. In one aspect you may be declaratively programming while in another you are doing so imperatively. Example: function constructARecord() { this.name=readFileLineNumber(fileName, 1); this.phone=readFileLineNumber(fileName, 2); this.address=readFileLineNumber(fileName, 3); } You are telling it how to construct a record, but you are not telling it how to read the file. Instead, you are just telling it to read the file. Anyway, enough of that diversion. I hope I've convinced you. When I finished writing the (half-working) partial order planner in Ruby, I mentioned I might like "to take actions as functions, which receive preconditions as their parameters, and whose output are effects" (let me give a special thanks to Hugh Sasse for his help and ideas in trying to use TSort for it while I'm on the subject). Doing so may have worked well when generalizing the solution to a rules engine instead of just a planner (they are conceptually quite similar). That's often intrigued me from both a business application and game programming standpoint. The good news is (as you probably already know), this has already been done for us. That was the subject of Venkat's talk that I attended at No Fluff Just Stuff at the end of June 2007. Why use rules-based programming? After a quick introduction, Venkat jumped right into why you might want to use a rules engine. The most prominent reasons all revolve around the benefits provided by separating concerns: When business rules change almost daily, changes to source code can be costly. Separation of knowledge from implementation reduces this cost by having no requirement to change the source code. Additionally, instead of providing long chains of if...else statements, using a rule engine allows you the benefits of declarative programming. A bit of theory The three most important aspects for specifying the system are facts, patterns, and the rules themselves. It's hardDrools Example