Convert .java to .class within a java program -
this question has answer here:
i have several .java files created during runtime. want use created .java files classes in program. how may this, without starting program second time ? want compile .java files during runtime , use new .class files on...
use java compiler api:
public class simplecompiletest { public static void main(string[] args) { string filetocompile = "test" + java.io.file.separator +"myclass.java"; javacompiler compiler = toolprovider.getsystemjavacompiler(); int compilationresult = compiler.run(null, null, null, filetocompile); if(compilationresult == 0){ system.out.println("compilation successful"); }else{ system.out.println("compilation failed"); } } }
Comments
Post a Comment