COMPILER API com.sun.javac.tools.javac before1.6 the compiler api was contained in package above javax.tools.* * compile a the class Test.java writing errors to a file JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); FileOutputStream errorStream = new FileOutputStream("Errors.txt"); int compilationResult = compiler.run(null, null, errorStream, "Test.java"); * compile 2 files JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); compiler.run(null, null, null, “One.java”, “Two.java”); * pass options to the java compiler with c.run() >> compiler.run(null, null, null, ”-classpath”, ”PathToClasses”, ”-sourcepath”, ”PathToSources”, ”One.java”, ”Two.java”); * compile with a diagnostic listener ------------------------------ AdvancedCompilationTest.java: package test; import java.io.*; import java.util.*; import javax.tools.*; import javax.tools.JavaCompiler.*; public class AdvancedCompilationTest { public static void main(String[] args) throws Exception { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); // Line 1. MyDiagnosticListener listener = new MyDiagnosticListener(); // Line 2. StandardJavaFileManager fileManager = compiler.getStandardFileManager(listener, null, null); // Line 3. String fileToCompile = "test" + File.separator + "ManyErrors.java"; // Line 4 Iterable fileObjects = fileManager.getJavaFileObjectsFromStrings( Arrays.asList(fileToCompile)); // Line 5 CompilationTask task = compiler.getTask(null, fileManager, listener, null, null, fileObjects); // Line 6 Boolean result = task.call(); // Line 7 if(result == true){ System.out.println("Compilation has succeeded"); } } } class MyDiagnosticListener implements DiagnosticListener{ public void report(Diagnostic diagnostic) { System.out.println("Code->" + diagnostic.getCode()); System.out.println("Column Number->" + diagnostic.getColumnNumber()); System.out.println("End Position->" + diagnostic.getEndPosition()); System.out.println("Kind->" + diagnostic.getKind()); System.out.println("Line Number->" + diagnostic.getLineNumber()); System.out.println("Message->"+ diagnostic.getMessage(Locale.ENGLISH)); System.out.println("Position->" + diagnostic.getPosition()); System.out.println("Source" + diagnostic.getSource()); System.out.println("Start Position->" + diagnostic.getStartPosition()); System.out.println("\n"); } } ,,, VARARGS * call a vararg method with an array. its ok >> addNumbers(new int[]{10, 34, 54}); *a vararg function definition ------------------------------------ public int addNumbers(int …numbers){ int total = 0; For(int temp : numbers){ Total = total + temp; } return total; },,,