Documentation

Documentation versions (currently viewingVaadin 23)
New Acceleration Kits: Observability Kit, SSO Kit, and Swing Kit. Read the blog post.

Live Reload

Live reload works seamlessly in development mode using HotswapAgent for runtime class and resource redefinition. You should run your Vaadin project with TravaOpenJDK Dynamic Code Evolution Virtual Machine (DCEVM), version 11.0.7+2 or later, which includes HotswapAgent with full live reload support. Setup is usually as easy as downloading the JDK and configuring your IDE to use it. If you want to know more about the features of HotswapAgent, the documentation in the HotswapAgent webpage is a good resource.

Step-by-Step Guide

  1. Download and unpack the latest version of DCEVM JDK, add the JDK to your IDE, and set your project / run configuration to use it. Alternatively, set JAVA_HOME to its location.

  2. In DCEVM 11.0.9 and later, HotswapAgent is disabled by default and needs the JVM parameter -XX:HotswapAgent=fatjar to work with Vaadin. Depending on your project technology stack, you may also want to apply additional configuration.

  3. Using your IDE’s debug command, start the Vaadin application in development mode.

  4. Navigate to a view in your application, edit any Java file in the project, recompile, and the browser automatically reloads the page with the changes.

Additional Configuration

  • HotswapAgent swaps in code changes automatically only when the JVM is running in debug mode. By default, the spring-boot-maven-plugin goal spring-boot:run forks a separate JVM without debugger attached, meaning that HotswapAgent doesn’t work. You can disable forked mode by adding <fork>false</fork> to the plugin’s <configuration> section.

  • To hot-swap code when the JVM isn’t in debug mode, you can add the line autoHotswap=true to hotswap-agent.properties (in Spring Boot projects), or add the JVM parameter -javaagent:<JAVA_HOME>/lib/hotswap-agent.jar=autoHotswap=true, where JAVA_HOME is the Java home of the TravaOpenJDK installation. Explicitly enabling automatic hotswapping may also be required with some older IDEs (such as NetBeans).

  • When using the Jetty Maven plugin together with HotswapAgent, ensure that automatic restart is disabled (omit or set <scanIntervalSeconds> to a value of 0 or less).

  • The live reload quiet time (milliseconds since last Java change before refreshing the browser) can be adjusted with the parameter vaadin.liveReloadQuietTime in hotswap-agent.properties. The default is 1,000 ms. Increase this value if you notice the browser refreshing before modified Java files have been fully compiled.

  • IntelliJ IDEA: avoid using the Build project automatically and compiler.automake.allow.when.app.running options simultaneously, since this may trigger automatic reload before classes are hotswapped.

Limitations

  • Since the server doesn’t restart, modifications to startup listeners and code that connects front-end and back-end components, such as adding a new LitTemplate class, aren’t reflected. However, modifications to routes are picked up.

  • With @PreserveOnRefresh, view instances are reused when reloaded in the browser; hence, hotpatched changes to the view constructor aren’t reflected until the view is opened in another browser window or tab.

  • The Vaadin plugin included in the bundled HotswapAgent (1.4.1) doesn’t work with servers that use application class loaders, for instance WildFly, TomEE or Payara. This bug is fixed in a prerelease version of HotswapAgent. To use it, download the JAR and pass the JVM parameter -XX:+DisableHotswapAgent -javaagent:<path/to/hotswap-agent.jar> to replace the bundled HotswapAgent with the fixed version.

403FEA6B-12A3-465C-9D6D-41DA902D9884