0

我有以下哪些代码用于使用 JavaCompiler 编译单个文件:

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromStrings(Arrays.asList(file.getAbsolutePath()));
JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, null, null, compilationUnits);
boolean success = task.call();
fileManager.close();

我的问题是:如何更改它以编译特定目录中的所有源文件?

4

1 回答 1

1

Get all the files from the directory (using directory.listFiles()), and pass the resulting array to getJavaFileObject(File...)

于 2012-06-08T21:56:53.920 回答