The example given by you illustrated how to create a new class and add fields ( methods) to that newly created class "someClass". If I want to store this newly created class into an external storage such as disk, LDAP, database etc. How can I write this "someClass" from Virtual Machine LoadTime to thoe external storages? More specifial requirments like this:
create an modified or new "someClass" by javasssit
output "someClass" to external storages as someClass.class , even someClass.java
I think this is doable and might your team already have done this.
ClassPool pool = ClassPool.getDefault();
CtClass cc = pool.makeClass("someClass");
CtClass ccObject = pool.get("java.lang.Object");
CtField field = new CtField(ccObject, "someField", cc);
You can use CtClass#writeFile() or
similar methods in ClassPool.