import javax.tools.JavaCompiler; import javax.tools.ToolProvider; /** * java的动态编译 * @author Administrator * */ public class Demo04 { public static void main(String[] args) { JavaCompiler compiler=ToolProvider.getSystemJavaCompiler(); int result = compiler.run(null, null, null, "c:\Test.java"); System.out.println(result==0?"编译成功":"编译失败"); } }