MVEL (MVFLEX Expression Language)
MVFLEX Expression Language (MVEL) is a hybrid dynamic/statically typed, embeddable Expression Language and runtime for the Java Platform.
MVEL3 is a complete rewrite of MVEL. Instead of interpreting expressions at runtime (as MVEL2 does), MVEL3 transpiles MVEL expressions into Java source code, compiles them in-memory via javac, and executes the resulting bytecode.
Alpha Notice: This is an alpha release. APIs may change in future releases.
Security Notice: MVEL expressions are functionally equivalent to Java code and can perform any operation the JVM allows, including file system access and network calls. Only compile and execute expressions from trusted sources. See SECURITY.md for details.
This is the MVEL version 3.x codebase, developed in the main branch.
MVEL2 is maintained separately in the mvel2 branch. If you contribute to MVEL2, please submit PRs to the mvel2 branch.
Prerequisites: JDK 17+, Maven 3.8.7+
MVEL3 requires a javaparser-mvel fork with MVEL-specific AST nodes. Build it first:
git clone https://github.com/mvel/javaparser-mvel.git
cd javaparser-mvel
mvn clean installThen build MVEL3:
git clone https://github.com/mvel/mvel.git
cd mvel
mvn clean installMVEL3 provides a fluent builder API with three context types: Map, List, and POJO.
Variables are passed via Map and extracted by name.
Map> types = new HashMap<>();
types.put("x", Type.type(int.class));
types.put("y", Type.type(int.class));
Evaluator, Void, Integer> evaluator =
MVEL.map(Declaration.from(types))
.out(Integer.class)
.expression("x + y")
.imports(Collections.emptySet())
.compile();
Map vars = new HashMap<>();
vars.put("x", 3);
vars.put("y", 5);
Integer result = evaluator.eval(vars); // returns 8Variables are extracted from a POJO via getter methods.
CompilerParameters params =
MVEL.pojo(Person.class,
Declaration.of("age", int.class))
.out(Boolean.class)
.expression("age > 20")
.imports(Collections.emptySet())
.classManager(new ClassManager())
.build();
Evaluator evaluator = new MVEL().compile(params);
Person person = new Person("John", 25);
Boolean result = evaluator.eval(person); // returns trueVariables are extracted from a List by positional index.
Declaration[] decls = new Declaration[]{
new Declaration("a", int.class),
new Declaration("b", int.class)
};
Evaluator, Void, Integer> evaluator =
new MVEL().compileListExpression(
"a + b",
Integer.class,
Collections.emptySet(),
decls
);
Integer result = evaluator.eval(List.of(3, 5)); // returns 8.expression("x + y")return to specify the return value..block("a = 4; b = 5; int c = 6; return a + b + c;")Use Type.type() to specify generic types:
types.put("names", Type.type(List.class, ""));
types.put("people", Type.type(List.class, ""));Pass a Set of fully qualified class names for types used in expressions:
Set imports = new HashSet<>();
imports.add("java.util.List");
imports.add(Person.class.getCanonicalName());No open issues yet, or sync has not completed.