Expressions4j a project intended to embed expressions to Java programs. The typical use-cases is when you need to generate expression from user input or expose some rules to configuration files.
-
Direct jars downloads: expressions4j-1.2
-
Plugin a maven repository to pom.xml
<repository> <id>scalemotion-open</id> <url>http://maven.scalemotion.com/open/</url> </repository>
and use it as dependency
<dependency>
<groupId>com.scalemotion.expressions4j</groupId>
<artifactId>expressions4j</artifactId>
<version>1.2</version>
</dependency>
- API is language-agnostic. Using some API you could treat expressions as Java or JavaScript (Groovy/Scala support is planned). Of cause, expressions syntax would be different for different language).
- Excellent API/Interoperability: it allows to expose functions/constants/variables to your expressions very easily
- It's lightweigh. It has zero dependecies. You should plug javassist/Rhino library to classpath depending on which language you're using.
System.out.println(new JavaExpressionCompiler().compile("return 2 + 2;", Object.class, int.class).evaluate(null));
//will output 4
System.out.println(new JSExpressionCompiler().compile("5 * 5;", Object.class, int.class).evaluate(null));
expressions4j has 0 runtime dependencies itself. However you should plugin javassist/rhino/both library depending of what kind of expressions are you going to use. expressions4j was tested with javassisit 3.12.1.GA and rhino 1.7R2. It also should work with higher major versions. If you're using maven you might plugin one of (or both): rhino js 1.7R2 javassist javassist 3.12.1.GA
The well documented examples is the best doc: https://github.com/ScaleMotion/expressions4j/blob/master/src/main/java/com/scalemotion/expressions4j/examples/Examples.java