java 加载源代码_运行时动态编译Java源代码并加载利用
发布日期:2021-06-24 11:14:17 浏览次数:2 分类:技术文章

本文共 534 字,大约阅读时间需要 1 分钟。

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

/**

* @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);

}

}

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

转载地址:https://blog.csdn.net/weixin_32424885/article/details/114513948 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:java memento_java设计模式-备忘录模式
下一篇:java blockingqueue源码_Java并发队列BlockingQueue实现之ArrayBlockingQueue源码分析

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月27日 20时30分33秒