JavaCompiler : Java Glossary


JavaCompiler is a Java version 1.6 or later interface that lets your program fire up the Java compiler, (usually javac.exe) and compile Java source, all under your program’s control, in a platform-independent way.

You don’t use exec or any more.

Benefits Learning More
Sample Code Links


The advantages of the JavaCompiler approach are:

Sample Code

JavaCompiler’s extreme generality and total lack of documentation makes it unusually inscrutable. The following example generates a Java source program on the fly in RAM, (It does not write it to disk.) and uses the default JavaFileManager to generate the class file in the CWD (Current Working Directory)
Note: the Hypotenuse.class file, that is dynamically generated by TestJavaCompiler in the CWD, must be accessible via the classpath to be able to load. For example, if the CWD is E:\myprojects\com\mindprod\example, then E:\myprojects must be on the classpath.
Here is what the dynamically generated file looks like:

In Java version 1.5 - you have the deprecated, undocumented to fire up the Javac.exe compiler to run in the same JVM and compile under your control.

Learning More

Oracle’s Javadoc on JavaCompiler class : available:
Oracle’s Javadoc on JavaFileObject class : available:
Oracle’s Javadoc on ForwardingJavaFileObject class : available:
Oracle’s Javadoc on SimpleJavaFileObject class : available:
Oracle’s Javadoc on JavaFileManager class : available:
Oracle’s Javadoc on ToolProvider class : available:

This page is posted
on the web at:

Optional Replicator mirror
on local hard disk J:

Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

Your face IP:[]
You are visitor number