Generating, compiling and using Java code at run time?

后端 未结 3 1535
陌清茗
陌清茗 2020-12-03 15:38

I have a scenario where I have to generate Java code when my application is running.

Can compile and run than code from my application( as a separate application).

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 16:15

    You can use an instance of JavaCompiler:

    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    

    Follow the link for the an example on how to use it.

提交回复
热议问题