It is very easy to invoke the compiler. Here is a sample call:
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); OutputStream outStream = ...; OutputStream errStream = ...; int result = compiler.run(null, outStream, errStream, "-sourcepath", "src", "Test.java");
A result value of
0 indicates successful compilation.
The compiler sends output and error messages to the provided streams. You can set these parameters to
null, in which case
System.err are used. The first parameter of the
run method is an input stream. As the compiler takes no console input, you can always leave it as
run method is inherited from a generic
Tool interface, which allows ...