Generating, compiling, and using Java code at runtime?

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

You can compile and run the code from my application (as a standalone application).

Is it possible to compile and then use it from one application. I can’t think of any possibility.

+6
source share
3 answers

Take a look Create dynamic applications using javax.tools . The second time I referred to today, I swear that I do not work for them.

+9
source

You can use an instance of JavaCompiler :

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 

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

+5
source

using ProcessBuilder or Runtime.exec () you can run any command line application from your java code

this includes the javac and java compiler as a separate process

+2
source

Source: https://habr.com/ru/post/888482/


All Articles