I need to generate class at runtime, each class is mapped to a database table. Such class is model class used in ORM.
When client specify a database table to work with, my application check for existence of corresponding model class , if it does not exist, generate it and load it for use and save it, so next time we don’t need to generate this class again
my question is:
- Is that possible?
- What open source library to use for generating class at runtime ?
some example code that illustrating how to generate simple POJO class is welcome!
best regards!
Yes, this is possible. And you don’t need an external lib. The JDK provides everything you need:
Check out the JavaCompiler docs.