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");            }     } } 

detailed example explanation


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -