Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top