I’m trying to obtain CtClass reference to my model class. I started with simpliest version
ClassPool.getDefault().get(className); and it worked fine. But only on my machine. It doesn’t work on server.
Anyway i think that the version shouldn’t work because Playframework stores classes in tmp/classses. So by now i finished with this version:
ClassPool pool = new ClassPool();
pool.appendClassPath(Play.applicationPath + "/tmp/classes");
CtClass cls = pool.get(className);
But i am not sure about this version. Will it work always? Are there better options?
I also tried using ClassClassPath and LoaderClassPath but without any success.
Usually you should not touch javassist class unless you are writing plugin and need to enhance the application code. in which case, you will have a
MyPluginEnhancer extends play.classloading.enhancers.Enhancer, then you can get the javassist class instance by callingmakeClass(ApplicationClass appClass)method.For a workable example, please refer to https://github.com/greenlaw110/play-morphia/blob/master/src/play/modules/morphia/MorphiaEnhancer.java.
PS: About
play.classloading.enhancers.Enhancer.makeClassmethod implementationWhere
classPoolcomes from the following code: