title: Get result of compiling a Java source file, within another Java class, using JavaCompiler package
body: <p>I have the following (simplified) code, within my class, which invokes the Java Compiler to process a given source file:</p>
  
  <pre><code>package test;
  import javax.tools.*;
  
  public class SimpleCompileTest {
      public static void main(String[] args) {
          String fileToCompile = "MyClass.java";
  
          JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
          int compilationResult = compiler.run(null, null, null, fileToCompile);
  
          if(compilationResult == 0){
              System.out.println("Compilation is successful");
          } else {
              System.out.println("Compilation Failed");
          }
      }
  }
  </code></pre>
  
  <p>The compilation succeeds, but now how can i get the result of MyClass.java, how to run this compiled code.</p>