Reputation: 4003
How does PlayFramework make code changes appear at runtime without restaring and redeploying? Does it use tomcat internally? If not, can I potentially put my Spring app on top of the server container it uses, and get the benefits of runtime changes.
Note: I know that it is technically possible to do that with Tomcat as well, however, form what I experienced, it is quite buggy, and does not work all the time. Sometimes, it even requires reloading the whole application context (which is around 16s), which goes off the point.
Upvotes: 2
Views: 999
Reputation: 6591
Play! doesn't use Tomcat or any other Servlet container. It runs on top of Netty, so it doesn't really follow the Java EE spec. However, you can assemble the app into war package to be deployed on Jetty/Tomcat/you-name-it-server.
I might be wrong in this, but Play! probably makes use of throwaway classloaders in order to load the new class definitions and this is why its reloading mechanism is better than regular hotswap.
Upvotes: 0
Reputation: 54914
Play works by, as Zenklys points out, checking the last modified date of the java files, and cross referencing them with the .class files that are generated at run time. If it recognises something has changed, then it recompiles them, at runtime.
In Play 1.x - the recompilation is done using the eclipse jdt compiler (org.eclipse.jdt.internal.compiler.Compiler). If you want to see the code from Play 1.x, just look at the following class - https://github.com/playframework/play/blob/master/framework/src/play/classloading/ApplicationCompiler.java
In Play 2.x, it looks as though Play does it by interlinking with the SBT tool. Check this out - https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/scala/play/core/system/ApplicationProvider.scala
Upvotes: 5
Reputation: 9255
If you are running within Eclipse with JBoss, you can point the JBoss deploy directory at your local project. As long as you aren't changing injections or method signatures, you can do code changes and they are recognized about 75% of the time. Since JBoss uses Tomcat as the servlet container, perhaps Tomcat can be set up in the same way.
Jrebel is also built specifically for this purpose.
Upvotes: -2
Reputation: 10404
First of all, this is only true when running in dev mode. In prod mode, changes are no longer detected.
As far, as I understood it, it is because the application is not run from .class file but from .java files. By observing last modified dates on those files, Play can detect when to re/compile the application.
What you are looking for something like JRebel.
Upvotes: 3