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

前端 未结 6 2068
北荒
北荒 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条回答
  •  庸人自扰
    2020-11-27 18:32

    If you're not completely tied to compiling, solutions like Beanshell, groovy and the other scripting languages are easily embedded (in-fact, java has built-in support for plugging in a scripting language so your code doesn't even know what language the script is written in)

    Beanshell should run any 100% java code IIRC, and I believe Groovy can run most java code--possibly all.

提交回复
热议问题