Compile a Java code : Java Compiler tools « JDK 6 « Java






Compile a Java code

 


import java.io.IOException;

import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;

public class JDK6FirstCompile {
  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));
  }
}

// File: MyClass.java
class MyClass {
  public static void main(String args[]) {
    System.out.println("Hello, World");
  }
}

        








Related examples in the same category

1.Compile a Java file with JavaCompiler
2.Java Compiler tools: how you can compile a Java source from inside a Java program
3.Compiling from Memory