Compiler Info : Java Compiler « Development « Java Tutorial






import java.util.Set;

import javax.lang.model.SourceVersion;
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;

public class CompilerInfo {
  public static void main(String[] args) {
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    System.out.println("Supported source versions:");
    Set<SourceVersion> srcVer = compiler.getSourceVersions();
    for (SourceVersion sv : srcVer)
      System.out.println("  " + sv.name());

    int nargs = compiler.isSupportedOption(args[0]);
    if (nargs == -1)
      System.out.println("Option " + args[0] + " is not supported");
    else
      System.out.println("Option " + args[0] + " takes " + nargs + " arguments");
  }
}








6.46.Java Compiler
6.46.1.JavaCompiler.run to compile
6.46.2.Enum Alternate Java Compilers
6.46.3.Compile String
6.46.4.Compile Java file
6.46.5.Compiler Info
6.46.6.Get classpath using System class
6.46.7.Programmatically compile Java class