// compiling from within a JVM // without spawning javac.exe or a separate JVM // com.sun.tools.javac.Main lives in tools.jar // Make sure tools.jar is on the classpath. It won't be by default. import com.sun.tools.javac.Main; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; // ... // simulate an arbitrarily long command line. // No wildcards since no command line interpreter to expand them. String[] optionsAndSources = { "-g", "-source", "1.5", "-target", "1.5", "Apple.java", "Banana.java", "Cantaloup.java"}; // where Javac output goes PrintWriter out = new PrintWriter( new FileWriter( "C:/temp/out.txt" ) ); // Compile all three sources at once int status = Main.compile( optionsAndSources, out ); out.println( "status: " + status );