JavaCompiler : Java Glossary

go to home page J words local find full screen, hide local find menu Google search web for more information on this topic jump to foot of page translate this page with Babelfish punctuation 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all) ©1996-2009 2006-02-18 Roedy Green, Canadian Mind Products
JavaCompiler
javax.tools.JavaCompiler is a JDK 1..6+ 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 JDK 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

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

CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/javacompiler.html J:\mindprod\jgloss\javacompiler.html
CMP logofeedback Please email your feedback for publication, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.191.109]
You are visitor number 6,658.