CompilationTask: call()
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
import javax.tools.JavaCompiler.CompilationTask;
public class Main {
public static void main(String[] args) throws Exception {
String sourceFile = "c:/HelloWorld.Java";
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
List<File> sourceFileList = new ArrayList<File>();
sourceFileList.add(new File(sourceFile));
Iterable<? extends JavaFileObject> compilationUnits = fileManager
.getJavaFileObjectsFromFiles(sourceFileList);
CompilationTask task = compiler.getTask(null, fileManager, null, null, null, compilationUnits);
boolean result = task.call();
if (result) {
System.out.println("Compilation was successful");
} else {
System.out.println("Compilation failed");
}
fileManager.close();
}
}
Related examples in the same category
1. | JavaCompiler: getStandardFileManager(DiagnosticListener super JavaFileObject> arg0, Locale arg1, Charset arg2) | | |
2. | JavaCompiler: getTask(Writer arg0, JavaFileManager arg1, DiagnosticListener super JavaFileObject> arg2, Iterable arg3, Iterable arg4, Iterable extends JavaFileObject> arg5) | | |
3. | JavaCompiler: isSupportedOption(String option) | | |
4. | Tool: run(InputStream in, OutputStream out, OutputStream err, String... arguments) | | |