Play. no need to compile

I became acquainted with the Play platform, and one of the amazing things I found about this is that there is no need to compile the project. You only need to save the edited files and reload the web page.

I was taught that Java source code was compiled into bytecode and then compiled with a JIT compiler, so what is the magic inside the Play framework?

+6
source share
3 answers

When working in DEV mode, playback works by checking the last modified date of java files and cross-referencing them with .class files that are generated at run time. If he recognizes something has changed, he will recompile them at runtime.

In Play 1.x, recompilation is performed 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 if Play does this by connecting to the SBT tool. Check it out - https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/scala/play/core/system/ApplicationProvider.scala

+11
source

Despite the fact that you did not mention which version of the game amazes you with such simple words, it can be described as follows: Play in development mode looks at all the files belonging to your application, and in case of any changes recompiles their parts. Therefore, DEV should not be used for production - as this is an excessive loss of productivity. Otherwise: when you run your application in production mode, this will avoid immediate recompilation, however, it will have performance.

In playback mode 2, the application works in development mode using

 play run 

or

 play ~run 

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

Launching the application in production mode can be done using

 play start 
+4
source

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

+1
source

Source: https://habr.com/ru/post/921577/


All Articles