On-the-fly, in-memory java code compilation for Java 5 and Java 6

前端 未结 6 2057
北荒
北荒 2020-11-27 18:17

How can I compile java code from an arbitrary string (in memory) in Java 5 and Java 6, load it and run a specific method on it (predefined)?

Before you flame this, I

6条回答
  •  -上瘾入骨i
    2020-11-27 18:28

    You might want to check out Janino as well.

    From their website:

    Janino is a compiler that reads a JavaTM expression, block, class body, source file or a set of source files, and generates JavaTM bytecode that is loaded and executed directly. Janino is not intended to be a development tool, but an embedded compiler for run-time compilation purposes, e.g. expression evaluators or "server pages" engines like JSP.

    http://www.janino.net/

    Im currently using it in a pretty large mission critical project and it works just fine

提交回复
热议问题