Did you know that you can compile Java source code from your running Java Application? It’s not even so hard and the JavaCompiler javadoc is quite verbose.
Try it for yourself:

package com.piotrnowicki.javacompiler; 

import javax.tools.JavaCompiler; 
import javax.tools.ToolProvider; 

public class Executor { 
    public static void main(String[] args) { 
        JavaCompiler jcp = ToolProvider.getSystemJavaCompiler(); 

        // Compile pointed *.java file
        jcp.run(null, null, null, "/home/piotr/MyClass.java"); 
    } 
} 

Now imagine that you can compile your Java code from a Java application that compiles your Java code. Why…? Because we can and because it’s so inception!  

Compiling in Inception
Did you like this? Share it:

Leave a reply

required


*

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>