1
votes

I have a standalone Java application, for which i have to integrate an Rules Engine. I should define Rules using a properties file or XML file. I need to have Rules Engine to read these rules defined in properties or XML file and accordingly implement code in application.

Any such Rules Engine (open-source), i can use it for my application. Please note that i do not want any Rules Engine which i need to deploy in Application Server or Web Server. I need to have some sort of jar file, where i can directly use this for my application.

Please guide me if there are any such Rules Engine i can make use of?

4
Have you already tried any software? If so, please mention this as well: you now may get suggestions which you may have already tried (and rejected). Also, could you explain a bit more about these rules (examples would help). - Bart Kiers

4 Answers

1
votes

You can go for Drools, which can be used in standalone programs as well.

http://www.jboss.org/drools

1
votes

Plug Alert!

I am biased as it is my own project, but if you want an extremely fast and lightweight rules engine, you can check out Roolie.

The philosophy behind the project is based on my personal experience that JSR-94 is overkill, most rules engines are too heavy, with too many dependencies and a steep learning curve.

Roolie does not address the "functional" rules that change application state (those should be Java anyway IMHO).

Instead, it allows the developer to implement simple rules with a single "passes" method, and chain them together with short-circuit boolean logic in an XML file. It has no runtime dependencies whatsoever, and is very fast.

It is a simple solution to a simple problem (i.e. Can the user see a file? Only if they are "logged in", "admin" OR "power user", and "has enough posts").

The composite rule would be "UserCanSeeFile" and would be comprised of "IsLoggedIn", "IsAdmin", "IsPowerUser", and "HasEnoughPosts".

If later you don't care how many posts they have to let them see a file, just yank that XML line and you are done.

1
votes

I experimented with a few expression evaluation libraries in java. I found MVEL to be the best. In my case i was reading "rules" from the database. So my rules looked like

player.platform == 'iOS' && ( player.ltv > 100 || player.status >= GOLD )

Now what i did was to parse above expression for all the variables. In my case a variable was any token with dot ( object.method ). It worked for me. Not sure if it will work you or not.

But once all variables were replaces with values. I just called an MVEL.evaluate().

Further in my case all expressions i needed to evaluate will give out in Boolean result. But MVEL can evaluate any expression with different result types.