Skip to content
Open
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
60 changes: 50 additions & 10 deletions articles/tools/modernization-toolkit/swing-bridge.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,15 @@ Add the following parent section, properties, and dependencies to your `pom.xml`
----
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<vaadin.version>24.9.10</vaadin.version>
<vaadin.version>25.1.0-beta1</vaadin.version>
<swing-bridge.version>1.0.0</swing-bridge.version>
<swing-bridge.path>${settings.localRepository}/com/vaadin</swing-bridge.path>
</properties>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.3</version>
<version>4.0.3</version>
<relativePath/>
</parent>

Expand Down Expand Up @@ -142,6 +141,12 @@ Add the following parent section, properties, and dependencies to your `pom.xml`
<groupId>com.vaadin</groupId>
<artifactId>swing-bridge-flow</artifactId>
<version>${swing-bridge.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand All @@ -152,10 +157,44 @@ Add the following parent section, properties, and dependencies to your `pom.xml`
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-dev</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
----

SwingBridge requires certain JVM flags so that Maven can access internal Java modules during compilation. Create a `.mvn/jvm.config` file in the project root with the following content:

.`.mvn/jvm.config`
[source]
----
--add-exports=java.desktop/sun.font=ALL-UNNAMED
--add-exports=java.desktop/sun.awt=ALL-UNNAMED
--add-exports=java.desktop/sun.awt.dnd=ALL-UNNAMED
--add-exports=java.desktop/sun.awt.dnd.peer=ALL-UNNAMED
--add-exports=java.base/sun.nio.cs=ALL-UNNAMED
--add-exports=java.desktop/sun.java2d=ALL-UNNAMED
--add-exports=java.desktop/sun.java2d.pipe=ALL-UNNAMED
--add-exports=java.desktop/sun.awt.datatransfer=ALL-UNNAMED
--add-exports=java.desktop/sun.awt.image=ALL-UNNAMED
--add-exports=java.desktop/java.awt.peer=ALL-UNNAMED
--add-exports=java.desktop/java.awt.dnd=ALL-UNNAMED
--add-exports=java.desktop/java.awt.dnd.peer=ALL-UNNAMED
--add-exports=java.desktop/sun.print=ALL-UNNAMED
--add-exports=java.desktop/sun.swing=ALL-UNNAMED
--add-opens=java.desktop/java.awt.event=ALL-UNNAMED
--add-opens=java.desktop/sun.awt=ALL-UNNAMED
--add-reads=java.desktop=ALL-UNNAMED
----

These flags are applied to the Maven JVM process itself, allowing the compiler to access the internal `java.desktop` module APIs that SwingBridge depends on. This is separate from the runtime JVM arguments configured in the build plugin below.

To launch the application through Maven CLI, add the following build plugin to your `pom.xml`:

.`pom.xml`
Expand Down Expand Up @@ -204,8 +243,10 @@ To launch the application through Maven CLI, add the following build plugin to y
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005
</jvmArguments>

<!-- JVM -D system properties -->
<systemPropertyVariables>
<java.awt.headless>false</java.awt.headless>
<!--<applibs.dir>${project.basedir}/some-lib-dir</applibs.dir>-->
</systemPropertyVariables>
</configuration>
</plugin>
Expand All @@ -226,12 +267,11 @@ Refer to the class that contains the main() method of your Swing application ins
[source,java]
----
@Route("myapp")
public class MyAppView extends VerticalLayout {

public MyAppView() {
add(new SwingBridge("com.mycompany.swingapp.MySwingAppMain"));
setSizeFull();
}
public class MyAppView extends VerticalLayout {
public MyAppView() {
add(new SwingBridge("com.mycompany.swingapp.MySwingAppMain"));
setSizeFull();
}
}

----
Expand Down