码迷,mamicode.com
首页 > 编程语言 > 详细

运行时动态编译Java源代码并加载利用

时间:2015-08-18 19:54:56      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:


  支持多个文件动态编译的代码段:

        /**
         * @param srcFiles
         */
        private void compileTheJavaSrcFile(File ... srcFiles) {
            try {
            	JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
                StandardJavaFileManager fileMgr = compiler.getStandardFileManager(null, null, null);
                CompilationTask t = compiler.getTask(null, fileMgr, null, null, null, fileMgr.getJavaFileObjects(srcFiles));
                t.call();
    			fileMgr.close();
    		} catch (Throwable e) {
    			throw new RuntimeException("Fail to compile files [" +  srcFiles + "]", e);
    	    }  
        }


运行时动态编译Java源代码并加载利用

标签:

原文地址:http://my.oschina.net/frankies/blog/494094

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!