[1.2] Where/How can I access the .class files in PROD mode? Problem with "Reflections"

98 views
Skip to first unread message

ogregras

unread,
Jan 3, 2012, 8:46:35 PM1/3/12
to play-fr...@googlegroups.com
I use Reflections ( http://code.google.com/p/reflections ) to get:

- classes annotated with a particular annotation
- fields annotated with a particular annotation

I don't think Play provide a way to get fields annotated with a particular annotation (in its ApplicationClasses and ApplicationClassloader classes).

In DEV mode, it works great when I provide Reflections with those "urls" to search the classes in:

#1 new File(Play.applicationPath + "/tmp/classes/").toURI().toURL()
or
#2 org.reflections.util.ClasspathHelper.forClassLoader(Play.classloader);

But In PROD mode:
#1 doesn't work since the .class files are not generated in the "tmp" folder.

#2 works on Windows, but not on my prod Linux box! I have no idea why! It seems Reflections is not able to find my application classes when using org.reflections.util.ClasspathHelper.forClassLoader(Play.classloader)! I also tried org.reflections.util.ClasspathHelper.forClassLoader(Thread.currentThread().getContextClassLoader()) but still no luck!

Any idea? Are some .class files actually generated somewhere in PROD mode?
How can I make Reflections aware of them?








ogregras

unread,
Jan 3, 2012, 9:35:09 PM1/3/12
to play-fr...@googlegroups.com
I understood why it was working on my local Windows machine: I was launching the application from within Eclipse, and  org.reflections.util.ClasspathHelper.forClassLoader(Play.classloader generated this url (among the others):

file:/C:/xxx/yyy/eclipse/classes/

But when I do "play run" at command prompt, it doesn't work, as on my Linux box!

So the question really is: where can I find the compiled classes in PROD mode?

Any idea?



ogregras

unread,
Jan 4, 2012, 7:51:33 AM1/4/12
to play-fr...@googlegroups.com
In fact, here's the question that would fix all my problems:

Can I force Play to generate the .class files, even in PROD mode?

ogregras

unread,
Jan 4, 2012, 7:05:32 PM1/4/12
to play-fr...@googlegroups.com
I finally found a "solution". It is an UGLY workaround, and I'm still very interested in a cleaner way to do this!

I created a plugin, and add this to its OnLoad() method:

======================
if(Play.mode == Play.Mode.PROD)
{
Logger.info("Workaround: Generating .class files even in PROD mode!");

Play.initialized = true;
Play.classloader.getAllClasses();
Play.initialized = false;
Logger.info("Workaround finished: .class files generated.");
}
====================== 

It seems "Play.initialized" must be true for the .class files to be generated. 
@see play.classloading.BytecodeCache.cacheBytecode()




ogregras

unread,
Jan 5, 2012, 3:48:29 PM1/5/12
to play-fr...@googlegroups.com
For the record: http://stackoverflow.com/a/8749231/843699

Instead of my ugly workaround, I now first precompile the application in PROD mode, then use "-Dprecompiled=true" to prevent compiling it again when I start the application!

Case closed! Thanks for the help everybody! ;-)
Reply all
Reply to author
Forward
0 new messages