Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
E

easy-rules

> 后端框架
Open source

The simple, stupid rules engine for Java

5.3K stars0 likes2 views
WebsiteGitHub

About

The simple, stupid rules engine for Java



Project status

As of December 2020, Easy Rules is in maintenance mode. This means only bug fixes will be addressed from now on. Version 4.1.x is the only supported version. Please consider upgrading to this version at your earliest convenience.

Latest news

  • 06/12/2020: Version 4.1 is out with a new module to support Apache JEXL as an additional supported expression language! You can find all details about other changes in the release notes.

What is Easy Rules?

Easy Rules is a Java rules engine inspired by an article called "Should I use a Rules Engine?" of Martin Fowler in which Martin says:

You can build a simple rules engine yourself. All you need is to create a bunch of objects with conditions and actions, store them in a collection, and run through them to evaluate the conditions and execute the actions.

This is exactly what Easy Rules does, it provides the Rule abstraction to create rules with conditions and actions, and the RulesEngine API that runs through a set of rules to evaluate conditions and execute actions.

Core features

  • Lightweight library and easy to learn API
  • POJO based development with an annotation programming model
  • Useful abstractions to define business rules and apply them easily with Java
  • The ability to create composite rules from primitive ones
  • The ability to define rules using an Expression Language (Like MVEL, SpEL and JEXL)

Example

1. First, define your rule..

Either in a declarative way using annotations:

java
@Rule(name = "weather rule", description = "if it rains then take an umbrella")
public class WeatherRule {

    @Condition
    public boolean itRains(@Fact("rain") boolean rain) {
        return rain;
    }
    
    @Action
    public void takeAnUmbrella() {
        System.out.println("It rains, take an umbrella!");
    }
}

Or in a programmatic way with a fluent API:

java
Rule weatherRule = new RuleBuilder()
        .name("weather rule")
        .description("if it rains then take an umbrella")
        .when(facts -> facts.get("rain").equals(true))
        .then(facts -> System.out.println("It rains, take an umbrella!"))
        .build();

Or using an Expression Language:

java
Rule weatherRule = new MVELRule()
        .name("weather rule")
        .description("if it rains then take an umbrella")
        .when("rain == true")
        .then("System.out.println(\"It rains, take an umbrella!\");");

Or using a rule descriptor:

Like in the following weather-rule.yml example file:

yaml
name: "weather rule"
description: "if it rains then take an umbrella"
condition: "rain == true"
actions:
  - "System.out.println(\"It rains, take an umbrella!\");"
java
MVELRuleFactory ruleFactory = new MVELRuleFactory(new YamlRuleDefinitionReader());
Rule weatherRule = ruleFactory.createRule(new FileReader("weather-rule.yml"));

2. Then, fire it!

java
public class Test {
    public static void main(String[] args) {
        // define facts
        Facts facts = new Facts();
        facts.put("rain", true);

        // define rules
        Rule weatherRule = ...
        Rules rules = new Rules();
        rules.register(weatherRule);

        // fire rules on known facts
        RulesEngine rulesEngine = new DefaultRulesEngine();
        rulesEngine.fire(rules, facts);
    }
}

This is the hello world of Easy Rules. You can find other examples like the Shop, Airco or WebApp tutorials in the wiki.

Contribution

You are welcome to contribute to the project with pull requests on GitHub. Please note that Easy Rules is in maintenance mode, which means only pull requests for bug fixes will be considered.

If you believe you found a bug or have any question, please use the issue tracker.

Awesome contributors

  • Alexey1Gavrilov
  • andersonkyle
  • aston2016
  • avakimov
  • beccagaspard
  • bpoussin
  • cgonul
  • cemo
  • dagframstad
  • danrivcap
  • Desislav-Petrov
  • drem-darios
  • gs-spadmanabhan
  • JurMarky
  • jordanjennings
  • kayeight
  • khandelwalankit
  • lranasingha
  • laurikimmel
  • mrcritical
  • paulbrejla
  • richdouglasevans
  • ruanjiehui
  • spearway
  • stefanbirkner
  • toudidel
  • vinoct6
  • wg1j
  • will-gilbert
  • WayneCui
  • sanmibuh
  • shivmitra
  • zhhaojie

Thank you all for your contributions!

Easy Rules in other languages

  • EasyRulesGo : A port of EasyRules to Golang by @jiminoc
  • EasyRulesGroovy : A port of EasyRules tutorials to Groovy by @will-gilbert
  • EasyRulesCsharp : A port of EasyRules to CSharp (WIP) by @feldrim

Who is using Easy Rules?

  • Apache Nifi (see Nifi EasyRules Bundle)
  • Open Remote (see build.gradle)
  • Open Smart Register Platform (see build.gradle)
  • Toad Edge by Quest
  • Extreme Networks

Credits

Many thanks to YourKit, LLC for providing a free license of YourKit Java Profiler to support the development of Easy Rules.

License

Easy Rules is released under the terms of the MIT license:

…

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Javabusiness-rulesexpression-languagejavarule-engine

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架