Skip to content

Explain how to install JBR manually #4352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: latest
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions articles/getting-started/run/generic.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
title: Generic
page-title: How to run a Vaadin application in any Java IDE
meta-description: Run your Vaadin application in any Java IDE and set up hotswap with JetBrains Runtime and HotswapAgent.
tab-title: Generic
order: 400
---


= Generic
:toclevels: 2

You can run and debug your Vaadin application in any IDE or editor that supports Java. The `Application` class has a `main()` method, that you should run. The application starts up and you'll be able to access it at http://localhost:8080. Hot deploy of the frontend files is enabled automatically. However, to enable Java hotswap, you have to take some additional actions.

== Enabling Hotswap Manually

To manually enable hotswap support for a Vaadin application, complete the following steps:

1. Install JetBrains Runtime (JBR)
2. Install HotswapAgent into JBR
3. Configure your IDE to launch your application with JBR and HotswapAgent


=== Install JetBrains Runtime

Download the latest _JetBrains Runtime with JCEF_ for your platform from the https://github.com/JetBrains/JetBrainsRuntime/releases[JetBrainsRuntime GitHub Releases] page. Choose a variant appropriate for your system (e.g., osx-aarch64, linux-x64, windows-x64):

Check warning on line 26 in articles/getting-started/run/generic.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vaadin.Abbr] 'JCEF' has no definition. Raw Output: {"message": "[Vaadin.Abbr] 'JCEF' has no definition.", "location": {"path": "articles/getting-started/run/generic.adoc", "range": {"start": {"line": 26, "column": 45}}}, "severity": "WARNING"}

* On macOS, use the `.pkg` installer, which installs JBR under:
`/Library/Java/JavaVirtualMachines/jbr_jcef-[version and platform]/Contents/Home`
* On Windows and Linux, download and extract the `.zip` or `.tar.gz` archive to a suitable location.

[NOTE]
The extracted directory contains a custom JVM with executables like `java` and `javac` inside the `bin/` folder. This is the JVM you'll use to run your application.


=== Install HotswapAgent

Download HotswapAgent (version 1.4.2 or later) from the https://github.com/HotswapProjects/HotswapAgent/releases[HotswapAgent GitHub Releases] page. Install it like this:

1. Create a subdirectory inside the JetBrains Runtime folder: `[JBR]/lib/hotswap/`
2. Rename the downloaded `.jar` file to `hotswap-agent.jar` and place it in that directory: `[JBR]/lib/hotswap/hotswap-agent.jar`

.More info
[NOTE]
Visit https://hotswapagent.org/[hotswapagent.org] for details about supported features and integrations.


=== Configure Application Launch with JetBrains Runtime and HotswapAgent

To run your application with Hotswap support, launch it using the JetBrains Runtime and provide the required JVM arguments. Use the `java` executable from your installed JetBrains Runtime and add the necessary -XX options for class redefinition.

.Example Command
[source,terminal]
----
/path/to/jbr/bin/java \
-XX:+AllowEnhancedClassRedefinition \
-XX:+ClassUnloading \
-XX:HotswapAgent=fatjar \
-cp <classpath> \
com.example.application.Application
----

Replace:

* `/path/to/jbr/bin/java` — with the full path to the java binary in your JetBrains Runtime installation.

Check failure on line 65 in articles/getting-started/run/generic.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vale.Terms] Use 'Java' instead of 'java'. Raw Output: {"message": "[Vale.Terms] Use 'Java' instead of 'java'.", "location": {"path": "articles/getting-started/run/generic.adoc", "range": {"start": {"line": 65, "column": 21}}}, "severity": "ERROR"}
* `<classpath>` — with your application's full classpath (use : as a separator on macOS/Linux, ; on Windows).

Check warning on line 66 in articles/getting-started/run/generic.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vaadin.Terms] Prefer 'divider' over 'separator'. Raw Output: {"message": "[Vaadin.Terms] Prefer 'divider' over 'separator'.", "location": {"path": "articles/getting-started/run/generic.adoc", "range": {"start": {"line": 66, "column": 70}}}, "severity": "WARNING"}
* `com.example.application.Application` — with the fully-qualified name of your application's main class.

[NOTE]
You may also set these VM arguments in your IDE's Run/Debug configuration, if it supports customizing the Java executable and arguments.


==== Enable Automatic Hotswap

If your IDE does not notify the hotswap agent of recompiled classes, you have to enable it manually. Create a new file `src/main/resources/hotswap-agent.properties` and put the following in it:

[source,properties]
----
autoHotswap=true
----


==== Compute the classpath

If you use a build script to run build and run your application, you can use the following to automatically generate the classpath on Linux/macOS:

[source,bash]
----
CLASSPATH=$(mvn dependency:build-classpath -Dmdep.outputFile=/dev/stdout -q):target/classes
----

A complete build script on Linux/macOS could look like this:

[source,bash]
----
#!/bin/bash
JBR_PATH="/path/to/jbr"
MAIN_CLASS="com.example.Application"
CLASSPATH=$(mvn dependency:build-classpath -Dmdep.outputFile=/dev/stdout -q):target/classes

$JBR_PATH/bin/java \
-XX:+AllowEnhancedClassRedefinition \
-XX:+ClassUnloading \
-XX:HotswapAgent=fatjar \
-cp "$CLASSPATH" \
"$MAIN_CLASS"
----


== Run and Verify Hotswap

Once configured, run your application using the command or launch configuration you've set up. Then:

1. Open the application in a browser.
2. Make a small change in your Java source code (e.g., update a label or log message).
3. Recompile the modified class (your editor or build tool *must support incremental compilation*).
4. HotswapAgent should automatically reload the updated class without restarting the application.

Check your application's logs — you should see messages from HotswapAgent confirming the class was reloaded. If nothing happens, verify that:

* The JVM used is JetBrains Runtime
* `hotswap-agent.jar` is correctly placed in `lib/hotswap/`
* All required JVM arguments are included
52 changes: 1 addition & 51 deletions articles/getting-started/run/vscode.adoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Visual Studio Code
page-title: How to run a Vaadin application in Visual Studio Code
meta-description: Run your Vaadin app in Visual Studio Code and enable Java hotswap with Vaadin Copilot or manual setup using JetBrains Runtime and HotswapAgent.
meta-description: Run your Vaadin app in Visual Studio Code and enable Java hotswap with Vaadin Copilot

Check warning on line 4 in articles/getting-started/run/vscode.adoc

View workflow job for this annotation

GitHub Actions / lint

[vale] reported by reviewdog 🐶 [Vaadin.Terms-App] Prefer 'application' over 'app'. Raw Output: {"message": "[Vaadin.Terms-App] Prefer 'application' over 'app'.", "location": {"path": "articles/getting-started/run/vscode.adoc", "range": {"start": {"line": 4, "column": 35}}}, "severity": "WARNING"}
tab-title: VS Code
order: 20
---
Expand Down Expand Up @@ -35,53 +35,3 @@
When you have completed all the steps, you can verify that everything is working. Start your application with hotswap enabled, and open it in a browser. Then select menu:Copilot[Development workflow] again. All the checkmarks should be green:

image::images/vscode-verified.png[Vaadin Copilot verifying that Java Hotswap is enabled]


== Enabling Hotswap Manually

Enabling hotswap manually consists of three steps:

1. Download and install JetBrains Runtime;
2. Download HotswapAgent and install it into JetBrains Runtime; and
3. Create a launch configuration for VS Code that runs the application with JetBrain Runtime and additional JVM parameters.

=== JetBrains Runtime

You can download the latest version from the https://github.com/JetBrains/JetBrainsRuntime/releases[JetBrains GitHub release page]. Be sure to select the correct architecture. Use JetBrains Runtime to execute your application, not necessarily your IDE.


=== HotswapAgent

You can download HotswapAgent from the https://github.com/HotswapProjects/HotswapAgent/releases[HotswapAgent GitHub release page]. You'll need version 1.4.2 or later.

Download the JAR file and place it inside the JetBrains Runtime installation directory as [filename]`lib/hotswap/hotswap-agent.jar`. You'll need to create the `hotswap` folder, and rename the downloaded file to `hotswap-agent.jar`.

If you want to know more about the features of HotswapAgent, the documentation in the https://hotswapagent.org/[HotswapAgent webpage] is a good resource.


=== Launch Configuration

Inside your Java project, create a new `.vscode/launch.json` file with the following contents:

[source,json]
----
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Application",
"request": "launch",
"mainClass": "com.example.application.Application", // <1>
"projectName": "my-application", // <2>
"javaExec": "/path/to/jetbrains-runtime/bin/java", // <3>
"vmArgs": "-XX:+AllowEnhancedClassRedefinition -XX:+ClassUnloading -XX:HotswapAgent=fatjar"
}
]
}
----
<1> Replace with your main class.
<2> Replace with the name of your project.
<3> Replace with the path to your JetBrains Runtime installation.

With the launch configuration in place, you can now start the application from the *Run and Debug* tab in Visual Studio Code. Open the application in a browser and verify that everything is working through menu:Copilot[Development Workflow].