Feeds:
Posts
Comments

Posts Tagged ‘javac’

How to create a dynamic class “on the fly” :

com.sun.tools.javac.Main class has two methods which help us to invoke the compiler from a program. It will behave like javac command.
public static int compile(String []args);
public static int compile(String []args , PrintWriter out);

args-> command line arguments that would be normally be passed on the javac program.
out-> indicates where the compiler’s output is directed.
return (int) -> exit value

I would like to share a simple program which will create a java file on the fly (ie at Runtime) and it will be compiled using compile method provided by this class com.sun.tools.javac.Main.Once itsĀ  been compiled,using reflection apis we will invoke the method in the class(which is created at Runtime).. (more…)

Read Full Post »