Setup and Configuration
Integrating Webswing with webforJ involves two components: the Webswing server that hosts your Swing app, and the WebswingConnector
component in your webforJ app that embeds it.
Prerequisites
Before you begin, make sure you have the following prerequisites:
- Java desktop app: a Swing, JavaFX, or SWT app packaged as a JAR file
- Webswing server: download from webswing.org
- webforJ version
25.10
or later: required forWebswingConnector
support
Architecture overview
The integration architecture consists of:
- Webswing Server: runs your Swing app, captures the GUI rendering, and handles user input
- webforJ Application: hosts your web app with the embedded
WebswingConnector
- Browser Client: displays both the webforJ UI and the embedded Swing app
Webswing and webforJ must run on different ports to avoid conflicts. Both webforJ and Webswing typically run on port 8080
. You should change either the Webswing port or the webforJ port.
Webswing server setup
Installation and startup
- Download Webswing from the official website
- Extract the archive to your preferred location (e.g.,
/opt/webswing
orC:\webswing
) - Start the server using the platform-specific scripts:
- Linux
- macOS
- Windows
webswing.sh
webswing.command
webswing.bat
- Verify the server is running by accessing
http://localhost:8080
Application configuration
Once the server is running, access the admin console at http://localhost:8080/admin
to add and configure your Swing app.
In the admin console, configure:
- Application Name: becomes part of the URL path (e.g.,
myapp
→http://localhost:8080/myapp/
) - Main Class: the entry point of your Swing app
- Classpath: path to your app JAR and dependencies
- JVM Arguments: memory settings, system properties, and other JVM options
- Home Directory: working directory for the app
After configuration, your Swing app will be accessible at http://localhost:8080/[app-name]/
webforJ Integration
Once your Webswing server is running with your Swing app configured, you can integrate it into your webforJ app. This involves adding the dependency, configuring Cross-Origin Resource Sharing (CORS), and creating a view with the WebswingConnector
component.
Add dependency
Add the Webswing integration module to your webforJ project. This provides the WebswingConnector
component and related classes.
<dependency>
<groupId>com.webforj</groupId>
<artifactId>webforj-webswing</artifactId>
</dependency>