sun.tools.javac.Main : Java Glossary
home S words local find no local find frame, full screen Google search web for topic jump to footer translate with Babelfish by Roedy Green ©1996-2008 Canadian Mind Products
Go to : 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)
sun.tools.javac.Main
Sun’s undocumented and deprecated interface to programmatically invoke the javac.exe compiler as a class that runs in your own JVM. It is replaced by javax.tools. JavaCompiler.

In JDK 1.5-, you have only an undocumented and hence deprecated technique of invoking the javac.exe compiler programmatically.

You normally invoke javac.exe from the command line, but you can also invoke it from within a Java program. Use the sun.tools.javac.Main class located in jdk1.6.0_06/lib/tools.jar to pass it an array of Strings equivalent to the command line parameters. You might do this to bulk-compile large numbers of files without reloading the javac compiler for each file. Here is how you use it:

This technique how ANT achieves its remarkable speed compiling large number of files. It does not keep loading java.exe over and over.

You too might use this technique for speed to avoid reloading javac.exe, or to have arbitrarily long command lines. You can also get long command lines with the @listOfFiles technique.

Capturing the error messages from javac.exe can be a hassle since they scroll off the screen faster than you can read them. Ordinary > redirection won’t capture them to a file because they are going to STDERR, not STDOUT. I use a program called 4NT to solve this problem. It lets you independently redirect STDOUT and STDERR. You can also use the -Xstdout to bypass the problem.

In Java 1.6+ programmatic invocation of the compiler will become an official interface. Read the JSR. For more details on how you do on the fly composing, compilation and execution see my sample code.


CMP_homejump to top
CMP logo
feedback Please email your feedback for publication, errors, omissions, broken/redirected link reports
and suggestions to improve this page to Roedy Green : feedback email
made with CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[65.110.21.43]
Your face IP:[38.103.63.16] The information on this page is for non-military use only.
You are visitor number 8,013. Military use includes use by defence contractors.
You can get a fresh copy of this page from: or possibly from your local J: drive (Java virtual drive/Mindprod website mirror)
http://mindprod.com/jgloss/javacmain.html J:\mindprod\jgloss\javacmain.html