JavaCompiler : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

JavaCompiler
javax.tools.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 sun.tools.javac.Main any more.

Benefits Learning More
Sample Code Links
sun.tools.javac.Main

Benefits

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 Hypotenuse.java file looks like:

sun.tools.javac.Main

In Java version 1.5 - you have the deprecated, undocumented sun.tools.javac.Main 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:

http://mindprod.com/jgloss/javacompiler.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\javacompiler.html
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.

IP:[65.110.21.43]
Your face IP:[3.149.231.122]
You are visitor number