List of usage examples for javax.tools ToolProvider getSystemJavaCompiler
public static JavaCompiler getSystemJavaCompiler()
From source file:Main.java
public static void main(String[] args) { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); int result = compiler.run(null, null, null, "Hello.java"); System.out.println("Compile result code = " + result); }
From source file:CompileFiles1.java
public static void main(String[] args) { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); compiler.run(null, null, null, args); }
From source file:FirstCompile.java
public static void main(String args[]) throws IOException { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); int results = compiler.run(null, null, null, "Foo.java"); System.out.println("Success: " + (results == 0)); }
From source file:Main.java
public static void main(String[] args) { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 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// www . j a v a2s. c o m System.out.println("Option " + args[0] + " takes " + nargs + " arguments"); }
From source file:CompilerInfo.java
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//from w w w . ja v a 2s . co m System.out.println("Option " + args[0] + " takes " + nargs + " arguments"); }
From source file:Main.java
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()); }/* w w w. j a va2s. c o m*/ }
From source file:CompileFiles2.java
public static void main(String[] args) { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector<JavaFileObject> dc; dc = new DiagnosticCollector<JavaFileObject>(); StandardJavaFileManager sjfm; sjfm = compiler.getStandardFileManager(dc, null, null); Iterable<? extends JavaFileObject> fileObjects; 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()); }// www.j a va 2 s . com }
From source file:DiagnosticCollectorCompile.java
public static void main(String args[]) throws IOException { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>(); StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null); Iterable<? extends JavaFileObject> compilationUnits = fileManager .getJavaFileObjectsFromStrings(Arrays.asList("Foo.java")); JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, null, null, compilationUnits);/*from w w w . j a va 2 s. c o m*/ boolean success = task.call(); fileManager.close(); System.out.println("Success: " + success); }
From source file:Main.java
public static void main(String args[]) throws IOException { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>(); StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null); Iterable<? extends JavaFileObject> compilationUnits = fileManager .getJavaFileObjectsFromStrings(Arrays.asList("YourFile.java")); Iterable<String> options = Arrays.asList("-d", "classes", "-sourcepath", "src"); JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, options, null, compilationUnits);/* w ww . j a va 2 s . c o m*/ boolean success = task.call(); for (Diagnostic diagnostic : diagnostics.getDiagnostics()) { System.out.println(diagnostic.getCode()); System.out.println(diagnostic.getKind()); System.out.println(diagnostic.getPosition()); System.out.println(diagnostic.getStartPosition()); System.out.println(diagnostic.getEndPosition()); System.out.println(diagnostic.getSource()); System.out.println(diagnostic.getMessage(null)); } fileManager.close(); System.out.println("Success: " + success); }
From source file:CompileString.java
public static void main(String[] args) throws Exception { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); String program = "class Test{" + " public static void main (String [] args){" + " System.out.println (\"Hello, World\");" + " System.out.println (args.length);" + " }" + "}"; Iterable<? extends JavaFileObject> fileObjects; fileObjects = getJavaSourceFromString(program); compiler.getTask(null, null, null, null, null, fileObjects).call(); Class<?> clazz = Class.forName("Test"); Method m = clazz.getMethod("main", new Class[] { String[].class }); Object[] _args = new Object[] { new String[0] }; m.invoke(null, _args);//w w w . j a v a 2s . c om }