Well then Ulf's link talks just exactly about that.
Joined: Apr 03, 2009
any other way to do this ?
Joined: Mar 22, 2005
What do you mean by "other way"? Is the suggested approach somehow not feasible in your situation? If so, tell us why it isn't.
Joined: Jul 01, 2008
I guess you would be looking for two separate functionalities
1 - To generate class dynamically . You can generate java class dynamically using com.sun.codemodel pacakage.
This package provides lots of functionality to generate class programmatically - including adding method, extending/implementing other class and interface.
2 - To compile and generate class file or fetch error in runtime.
For this, you can use sun package - com.sun.tools.javac.Main to compile and to parse result or compiler error there are utility classes provided by apache in the package - org.apache.commons.jci.compilers and org.apache.commons.jci.problems
We are generating, compiling lot of classes dynamically based on user input. Later we are invoking the classes and storing the execution result in our database.