Java 动态编译

店铺:https://shop58616120.taobao.com

一、JavaCompiler编译

importjavax.tools.ToolProvider;
public class JLang {
    public static void main(String[] args){
                javax.tools.JavaCompiler compiler = 

                ToolProvider.getSystemJavaCompiler();
        int result = compiler.run(null, null, null, "JavaFilePath");
                System.out.println(result==0? "Ok" : "Fail");
        }
}

参数说明

二、动态运行

1. 通过Runtime.getRuntime()


2. 通过反射运行编译好的类

评论

© Saoirse | Powered by LOFTER