How to develop Vaadin apps without servlet container restarts
Vaadin Flow is based on Java and a Servlet-Container. To see results, you need to deploy the Flow app, and the servlet container must run. This startup will take a few seconds based on your computer and the project. How could we get this turnaround time reduced? What should we do to speed up the development? The answer is called DCEVM and Hotswap.
DCEVM is an extension to the JVM that will allow us to reload classes at runtime more easily. It is based on the OpenJDK version 8 and 11 so far. Maybe, more versions are available in the future. Check the DCEVM-website for this http://dcevm.github.io/ To use this, you need to download the version you need (version 8 or 11) also, start the installer with the command. java -jar installer.jar Follow the instructions that the UI will give you. To make it easier to switch between a JDK with and without DCEVM you should use a dedicated installation of the JDK for this. The primary process is the following:
java -jar installer.jar
press the button "Add installation directory."
select the folder of the JDK you want to use
decide if you’re going to have it as a replacement and/or alternative JVM configuration
close the app
After this is done, we need the second part called HotSwapAgent http://hotswapagent.org/. In contrast to standard Java, where the hot-swap is limited to in-body code changes, the DCEVM + HotswapAgent allow following code changes:
Add/remove/modify class fields.
Add/remove/modify methods. Add/remove/modify method annotations
Add/remove/modify classes including anonymous classes. HotswapAgent handless correct anonymous class redefinitions.
Add/remove a static member of classes. HotswapAgent handles static member initialization.
Add/remove enum values
Refresh framework and application server settings
The only unsupported operation is hierarchy change (change the superclass or remove an interface). DCEVM does hot-swap on JVM level. HotwapAgent does the same on the level of Java frameworks and servlet containers.
To activate HotSwapAgent, download the binary for your JDK (version 8 or 11 is supported right now) and enable this agent during the start of the JVM. -javaagent:hotswap-agent.jar There are a lot of different Plugins available; Vaadin Support is one of them.
If you are done with these preparations, you should start your Vaadin project in Debug mode using the DCEVM extended JDK. Do not forget to activate the HotSwapAgend (-javaagent:hot-swap-agent.jar) After you changed a class, re-compile it and refresh the Flow web app in the browser. That is it.