Compiling external .java files from within Java -
i making tool write .java files, (hopefully) compile files .class files. in 1 process, user selects file directory multiple .java files written. want program compile these java files.
javacompiler friend. check documentation here
and here example on how use compiler api
javacompiler compiler = toolprovider.getsystemjavacompiler(); diagnosticcollector<javafileobject> diagnostics = new diagnosticcollector<>(); standardjavafilemanager filemanager = compiler.getstandardfilemanager(diagnostics, null, null); iterable<? extends javafileobject> compilationunits = filemanager.getjavafileobjectsfromstrings(arrays.aslist("youfiletocompile.java")); javacompiler.compilationtask task = compiler.gettask(null, filemanager, diagnostics, null, null, compilationunits); boolean success = task.call(); filemanager.close();
Comments
Post a Comment