Compile Java Files At Runtime

Posted on March 18, 2012

Java 6 has a new Compiler API, as a result of JSR 199, which requests for a standard way to compile java source files. Although I use a lot of Java, I don't get to use some of the Java API's, as they are not required for the business functionality that I usually code. So, I was looking around for some new ideas or code to try and thought of working on a simple Java IDE and got to work on JavaCompiler class from package of Java 6. Here's a naive example, that shows how to compile a Java source file at runtime:

Blog Categories
The views expressed on this blog are my personal views and do not reflect the views of my employer or campaigns I am supporting.

All sample code is provided for illustrative purposes only. These examples have not been thoroughly tested under all conditions. The writer therefore, cannot guarantee or imply reliability, serviceability, or function of these programs.

All programs contained herein are provided to you "AS IS" without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.