Dynamic code execution

For real Java code, this is possible using the JavaCompiler interface. However, it’s very inconvenient to use since it’s just an interface to a real Java compiler that expects to compile entire class definitions found in files.

The easiest way to execute code supplied at runtime would be to use the Rhino JavaScript engine.

Both of these options have been only in Java 6, though I believe the scripting interface existed before, so you could use Rhino in an earlier JRE if you download and add it to the classpath.

Leave a Comment