JavaCompiler: getTask(Writer arg0, JavaFileManager arg1, DiagnosticListener arg2, Iterable arg3, Iterable arg4, Iterable arg5) : JavaCompiler « javax.tools « Java by API






JavaCompiler: getTask(Writer arg0, JavaFileManager arg1, DiagnosticListener arg2, Iterable arg3, Iterable arg4, Iterable arg5)

      
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 arg0, Locale arg1, Charset arg2)
2.CompilationTask: call()
3.JavaCompiler: isSupportedOption(String option)
4.Tool: run(InputStream in, OutputStream out, OutputStream err, String... arguments)