This page demonstrates how to enable hotswap when developing Vaadin applications using CDI (Context and Dependency Injection,the standard dependency injection framework for Java EE).
We assume that you are using Apache TomEE with the tomee-maven-plugin, starting the server by running the goal
tomee:run. Configure the plugin as follows in the
<plugins> section of
<plugins> <plugin> <groupId>org.apache.tomee.maven</groupId> <artifactId>tomee-maven-plugin</artifactId> <version>7.1.1</version> <configuration> <tomeeClassifier>webprofile</tomeeClassifier> <context>ROOT</context> <synchronization> <extensions> <extension>.class</extension> </extensions> </synchronization> <reloadOnUpdate>true</reloadOnUpdate> <systemVariables> <openejb.system.apps>true</openejb.system.apps> <tomee.serialization.class.blacklist>-</tomee.serialization.class.blacklist> </systemVariables> </configuration> </plugin> <!-- more plugins --> </plugins>
The configuration enables auto-reload and ensures that any change to a file with the extension
.class (a Java recompile) triggers the TomEE server reload (you will still need to refresh the browser page).
Note that if you base your project on the Vaadin CDI starter (from https://vaadin.com/start), the above configuration is already done for you.
During the hotswap cycle, the session is serialized before the server is stopped and deserialized after restarted. This means that user login and other session-based data is still available.
During hotswap, the TomEE log may contain warnings about memory leaks due to the webpack server and watchdog process not being terminated. These can safely be ignored.
If a class with a
@Routeannotation is removed, the route given in the annotation is still navigable after reload. Note that this is not a problem when only modifying the route of a view, without deleting the Java class.
Other popular CDI-enabled servlet containers include WildFly, JBoss EAP, GlassFish, IBM WebSphere and Oracle WebLogic. Some of these come with IDE integrations that enable hot reloading of application code. If you develop a Vaadin application against one of these application servers, please consult the provider for available developer tooling.