Is it possible to compile and emit .class files at run time? I have some generated servlet code and I want to compile them into classes and package it as a war.
Thanks.
Is it possible to compile and emit .class files at run time? I have some generated servlet code and I want to compile them into classes and package it as a war.
Thanks.
Yes, it is.
You can take a look at the Java Compiler API doc
Note however, that you will have to provide the corresponding ClassLoader and manage all the resources yourself.
If you want to generate bytecode from non-Java sources, you can also use ASM directly:
Just export the generated codes into files in a temp directory, invoke javac in there, package them, serve them. Nothing fancy needed.