Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play framework. no need to compile

I was introduced to the Play framework, and one of the amazing things I found about it is that there is no need to compile the project. You only need to save the edited files and reload the webpage.

I've been taught that Java source code is compiled to bytecode and then compiled with the JIT compiler, so what is the magic inside of the Play framework?

like image 514
socksocket Avatar asked Jul 28 '12 21:07

socksocket


People also ask

Is Play Framework asynchronous?

Internally, Play Framework is asynchronous from the bottom up. Play handles every request in an asynchronous, non-blocking way. The default configuration is tuned for asynchronous controllers.

How do I run a Play Framework?

To run a Play application: Create a new Run Configuration – From the main menu, select Run -> Edit Configurations. Click on the + to add a new configuration. From the list of configurations, choose “sbt Task”

Why Play Framework is used?

Play Framework makes it easy to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly architecture. Built on Akka, Play provides predictable and minimal resource consumption (CPU, memory, threads) for highly-scalable applications.

How do I run a debug in Play Framework?

To debug, start your application with activator -jvm-debug 9999 run and in Eclipse right-click on the project and select Debug As, Debug Configurations. In the Debug Configurations dialog, right-click on Remote Java Application and select New. Change Port to 9999 and click Apply.


3 Answers

When running in DEV mode, Play works by 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

like image 60
Codemwnci Avatar answered Oct 22 '22 20:10

Codemwnci


Although you didn't mention which version of Play amazed you so much in simplest words it can be described that way: Play in development mode watches all files that belongs into your app, and in case of any change it recompiles required parts. Therefore DEV should not be used for production - as it is redundant loss of the performance. Otherwise: when you'll start your application in production mode it will avoid immediate recompiling, however it will gain the performance.

In Play 2 running the application is development mode done with

play run

or

play ~run

(first command recompiles code after next page hit, second after next file change)

Running application in production mode can be done with

play start
like image 28
biesior Avatar answered Oct 22 '22 20:10

biesior


If you are talking about Play framework 1.x, it has an application class manager, which automatically load the java source file and compile it into byte code (using Eclipse Java Compiler), in additional it will enhance the compiled code using Javassist. Check the codes in https://github.com/playframework/play/tree/master/framework/src/play/classloading.

like image 26
Gelin Luo Avatar answered Oct 22 '22 20:10

Gelin Luo