DEV Community

Yuliya Sheludyakova
Yuliya Sheludyakova

Posted on

Auto-build and dynamic deployment with IntelliJ and TomEE

Hello πŸ‘‹

I would like to share a quick tip with you about how to configure a live reload and recompilation of your code changes in a Java project.

This post could be helpful if you use:

  • Java EE with the TomEE server and cannot (or do not want to) use third-party tools like JRebel
  • IntelliJ IDEA as an IDE (my version is 2020.3.1)
  • Maven as a build tool

To reload code changes immediately and see the corresponding effects in the browser without restarting the server, you should take the following steps.

TomEE dynamic deployment configuration

Add the tomee-maven-plugin to your pom.xml file and configure it like this. The key properties are extensions, reloadOnUpdateand openejb.system.apps.

<plugin>
    <groupId>org.apache.tomee.maven</groupId>
    <artifactId>tomee-maven-plugin</artifactId>
    <version>${tomee.version}</version>
    <configuration>
        <tomeeClassifier>plus</tomeeClassifier>
<!-- adjust the context name according to your project -->
        <context>ROOT</context>
        <synchronization>
            <extensions>
<!-- used for detecting code changes in Java classes -->
<!-- if needed, add other extensions (like .properties)-->
                <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>
Enter fullscreen mode Exit fullscreen mode

Then, run your project with clean package tomee:run

IntelliJ IDEA auto-build configuration

After a code change, the project should be recompiled. You can do this through:

  • mvn compile command -> in my project this takes around 10 seconds and must be done manually
  • auto-build functionality in IntelliJ IDEA -> takes around 3-4 seconds and is, well... automatic!

To be able to use the auto-build, do the following steps:

  1. File > Settings > Build, Execution, Deployment > Compiler > "Build project automatically" > Apply
  2. Open the Action window with Ctrl+Shift+A and type in Registry
  3. Search for compiler.automake.allow.when.app.running and compiler.document.save.enabled and check a checkbox
  4. To speed up the auto-build, reduce the value of compiler.automake.postpone.when.idle.less.than (e.g. to 1500 ms)

As the last step, refresh your browser page and... voilà 😊

Please keep in mind: if your project has several independent modules, the dynamic deployment will only work for the module, in which you have configured the tomee-maven-plugin.

By the way, this is my first post on Dev.to and I hope it could help someone 😊

Top comments (0)