Compiling a Java file with code from a Java file
You can also use Groovy , which is great if you just want to compile and run a line or two of Java code from within your application. The application can be in regular Java, and Groovy is only used to compile dynamically generated code. Whichever solution you choose, be careful as performing user input as the code can lead to security issues (injection vulnerability).
source to share
I agree with @eee's comment, which javax.script
is probably very suitable for your project, script code is easier to deal with than Java code. I've used it successfully in the past for plugin APIs, I don't remember having trouble getting it up and running.
Most projects I know about compiling real Java at runtime use the Eclipse compiler . Java 6 javac
can be accessed entirely programmatically. I've never used any of these myself. These two and some other compilers can be accessed through the Commons-JCI if needed.
source to share