compiler construction - Compile Java source code from a string? -


this question has answer here:

is there way running java program compile java source code (passed string)?

class newclass = compiler.compile ("class abc { void xyz {etc. etc. } }"); 

ideally, classes referenced passed-in source code resolved program's class loader.

does exist?

sure. have @ javacompiler class , other classes in javax.tools package.

they've been around since java 1.6.

here example code.

(as pointed out @sergey tachenov in comments, needs jdk installed necessary tools.jar file comes jdk not jre.)


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -