How does the Play Framework function?

Play uses the Eclipse compiler to compile code at run-time.

Take a look at the following class, that is used by Play to perform the necessary compilation at run time.

https://github.com/playframework/play/blob/master/framework/src/play/classloading/ApplicationCompiler.java


I've compared Play(+Scala) to Lift+mvn scala:cc+JRebel. Play is much better experience. Now, I know the reason:

Play is stateless. So, it can unload the Controller, forget all the fields and load+initialize it again. JRebel is aimed to be much more generic. It assumes that the state is important, so it sometimes (frequently?) fails, because it can't preserve the state in some cases.


This is the marvelous magic of runtime compilation/classloaders and javassist...

But don't forget that in prod environment, it's not like Groovy that basically recompiles your scripts into Java classes at runtime (unless you precompile your scripts naturally). In prod, Play! runs with real compiled classes so it's as efficient as classic java code. Moreover, it's not like Spring or other frameworks that uses lots of AOP with lots of overhead between your function call and your real business code.

IMO, it's a really clever design ;)