Pregunta

I have the following which code which is being used to compile single files with 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();

My question is: How do I change this to compile all source files in a particular directory?

¿Fue útil?

Solución

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top