openxava / documentation / Hot code reloading with OpenXava Studio / Java 11

×News: OpenXava 7.7.3 released - June 8 · Read more

Table of contents

Hot code reloading with OpenXava Studio / Java 11
Java included in OpenXava Studio 7 R4
IntelliJ
Visual Studio Code

This document covers hot code reloading for the now discontinued OpenXava Studio and for Java 11. If you are using IntelliJ or a modern Java version (17, 21 or 25), please refer to the current documentation: Hot code reloading.

Java included in OpenXava Studio 7 R4

For code reloading to work, it's necessary to run the application with the Java included in OpenXava Studio 7 R4. This Java is a JDK 11 based on DCEVM that integrates HotswapAgent, and is specially tuned to work well with OpenXava's hot reloading.
This JDK is found in the OpenXava Studio 7 R4 distribution, in openxava-studio-7-r4/studio/jre.
If you run OpenXava Studio on a clean machine without Java and in a new workspace, this Java should be used by default. However, if you already have other JDKs on your computer or have a workspace where you've registered other JDKs, your application might not be using the JDK with HotswapAgent and therefore class reloading won't work.
You'll know if you're running the correct JDK if you see these lines in the log when starting your application:
HOTSWAP AGENT: 13:40:23.126 INFO (org.hotswap.agent.HotswapAgent) - Loading Hotswap agent {1.4.1} - unlimited runtime class redefinition.
Starting HotswapAgent '/home/theuser/openxava-studio-7-r4/studio/jre/lib/hotswap/hotswap-agent.jar'
If not, in OpenXava Studio, go to Window > Preferences > Java > Installed JREs and verify that you have a JRE pointing to openxava-studio-7-r4/studio/jre, as shown here:
openxava-studio-7r4-jre.png
If it's not there, add it yourself. Also, remove any other Java 11 you have registered. Try running your application again.
If it still doesn't run Java with HotswapAgent, you might have Java 1.8 recognized by OpenXava Studio and your project might be configured to work with Java 1.8, so it chooses Java 1.8 instead of Java 11 (the one from OpenXava Studio). To fix this, go to your project's pom.xml and change:
<properties>
    ...  
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>
To:
<properties>
    ...  
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
</properties>
Then right-click on your project and choose Maven > Update Project... This should make it work.
If you want to continue compiling with Java 1.8 and therefore don't want to change the pom.xml, that's not a problem. Go to Run Configurations:
eclipse-run-configurations.png
Find your application and in the JRE folder, make sure your application runs with the OpenXava Studio JDK:
run-configuration-jre.png
If not, change it - you might need to use the Alternate JRE option.

IntelliJ

You can also enjoy hot code reloading using IntelliJ. The trick is to run the application with the JDK included in OpenXava Studio 7 R4. You'll need to download OpenXava Studio, even if it's just to use its JDK.

Register the JDK included in OpenXava Studio 7 R4 in your IntelliJ. Go to File > Project Structure. There in the SDKs section add the JDK found in openxava-studio-7-r4/studio/jre:

intellij-openxava-studio-jdk-definition.png

Then in the Project section, choose this JDK as the SDK for the project:

intellij-openxava-studio-jdk-for-project.png

Keep in mind that IntelliJ does not compile the code automatically when the application is running, so after changing the code you have to press the Build button, the one with the little hammer, for it to compile and be able to see the updated changes.

Visual Studio Code

To use hot code reloading with Visual Studio Code you need to run the application with the JDK included in OpenXava Studio 7 R4, so you'll need to download OpenXava Studio, even if it's just to use its JDK.
For Visual Studio Code to recognize your JDK add this to your user's settings.json:

"java.configuration.runtimes": [
    {
        "name": "JavaSE-11",
        "path": "/home/youruser/openxava-studio-7-r4/studio/jre",
        "default": true
    }
]

Visual Studio Code compiles the code automatically as you edit it, just like OpenXava Studio, so you just have to touch the code and go to the browser to see the application changed immediately.