Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import javax.tools.Diagnostic;
import javax.tools.DiagnosticCollector;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;

public class Main {
    public static void main(String[] args) {
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        DiagnosticCollector<JavaFileObject> dc = new DiagnosticCollector<JavaFileObject>();
        StandardJavaFileManager sjfm = compiler.getStandardFileManager(dc, null, null);
        Iterable<? extends JavaFileObject> fileObjects = sjfm.getJavaFileObjects(args);
        compiler.getTask(null, sjfm, dc, null, null, fileObjects).call();
        for (Diagnostic d : dc.getDiagnostics()) {
            System.out.println(d.getMessage(null));
            System.out.printf("Line number = %d\n", d.getLineNumber());
            System.out.printf("File = %s\n", d.getSource());
        }
    }
}