问题描述
javax.tools.JavaCompiler 是否可以编译文件但将字节码返回到 byte[] 中而不实际创建 .class 文件?我当前的代码:
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler
.getStandardFileManager(diagnostics,null,null);
Iterable<? extends JavaFileObject> compilationunit = fileManager
.getJavaFileObjectsFromFiles(Arrays.asList(filetoCompile));
JavaCompiler.CompilationTask task = compiler
.getTask(osw,fileManager,diagnostics,compilationunit);
task.call()
filetoCompile.delete();
fileManager.close();
在上面的代码中,filetoCompile
是一个 File
。我还想用要编译的 .java 文件的 File
或 byte[]
替换此 InputStream
。提前致谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)