logo
25.1
search
No matching documents found.
list
search
No matching documents found.
logo

Swing/JavaFX

Application Setup

Swing and JavaFX applications are configured in json format and by default are saved in file webswing.config, which is by default placed in the same folder as the webswing-server.war file. This location may be changed using the -c command-line option. It is recommended to use the Administration console form based configuration screen to modify this file to avoid JSON formatting problems.

Configuration using Admin Console

The easiest way of configuring your application is using the Admin console. To access the Admin console click Manage from Webswing homepage or go to the admin console URL that you have configured in your webswing.config file under root ("/") path. Navigate to the Configuration view where you can see the list of configured applications. You can add new or edit existing applications here.

Configuration

You can edit or view the settings. These are split in logical sections. Each setting has a description, which is displayed when hovered on the question mark.

Description

JSON format description

There are 3 config files:

  1. Standalone Webswing config
  2. Cluster server config
  3. Cluster session-pool config

Configuration File Organization

The JSON configuration file is organized by the unique URL endpoints. Each URL endpoint has therefore its own configuration. This can be seen in the Webswing binary distribution webswing.config file:

{
  "/" : {
    "path" : "/",
    "security" : ...
    },
    ...
  },
  "/swingset3" : {
    "path" : "/swingset3",
    "name" : "SwingSet3",
    "security" : {...},
    ...
    "swingConfig" : {
      ...
      "launcherType" : "Desktop",
      "launcherConfig" : {
        "mainClass" : "com.sun.swingset3.SwingSet3",
        "args" : null
      },
    },
  },
  "/netbeans" : {
    "path" : "/netbeans",
    ...
  },
  "/applet" : {
    "path" : "/applet",
    ...
  },
  "/javafx" : {
    "path" : "/javafx",
    ...
}

Variable resolution

Most of the text options support variable replacement. Available variables are Java system properties, OS environment variables, and a set of special Webswing variables. Variables are specified with dollar followed by variable name in curly brackets. For example, ${variable_name}.

In additions to variables, for classPathEntries properties it is possible to use wild-card characters. Supported wild-cards are * (everything) and ? (any singe character).

Available variables:

Variable Name Description
${user} Webswing specific logged in user name.
${clientId} Webswing specific unique browser identifier.
${clientIp} IP address of browser that started this application.
${clientLocale} Locale of browser that started this application.
${clientTimeZone} Time zone of browser that started this application.
${customArgs} Custom Arguments specified in URL parameters. See details
Java system Properties All properties accessible to server's JVM using System.getProperty method
System environment variables All OS level environment variables accessible to script that started Webswing server JVM.

In Admin Console, options which support variable replacement show with a flash icon. Click on the flash icon shows the resolved value:

Variable Resolution

Data store

Data store is a configuration of storage for files that are transferred between the browser and application instance.

You can configure different data store per application or configure a single data store for root ("/") and inherit the configuration by applications. By default, there is a File Store data store configuration used. This data store stores the data to file system to ${webswing.rootDir}/datastore folder.

If you need a different type of data store, please contact support@webswing.org.

Custom startup script

Sometimes, it is necessary to prepare the environment before the application process is started. This may include steps like changing the current working directory or using sudo to run application as a different user. This can be achieved by pointing the jreExecutableoption to custom startup script.

Custom startup script must follow a few rules in order to work with Webswing:

  1. The last step of the script should execute Java with the arguments as passed in by Webswing. (ie. $JAVA_HOME/bin/java $@ )
  2. If the script has arguments of its own, they should be shifted before calling Java (shift 3 if your script uses 3 arguments)
  3. Be aware that variable resolution in webswing.config is done in the server's context (the environment changes will not be reflected to variables defined in webswing.config).

Here is an example of the custom script that will use sudo to run the application process as the logged in user. We assume that users defined in users.properties have OS level counterparts and the user used to start the server is properly configured in sudoers (needs NOPASSWD flag in sudoers - see man page).

Here is our application configuration:

{
    "name" : "SwingSet3",
    "jreExecutable": "startSwingSet3.sh ${user}",
    "javaVersion": "1.8",
    "mainClass" : "com.sun.swingset3.SwingSet3",
    "classPathEntries" : [ "SwingSet3.jar", "lib/*.jar" ],
    "vmArgs" : "-Xmx128m",
    "args" : "",
    "homeDir" : "demo/SwingSet3"
}

When Webswing starts an application with the above configuration, the command-line will look like this:

startSwingSet3.sh johnDoe -Xmx128m <webswing specific configuration> -cp webswing-server.war main.Main

Now the custom script demo/SwingSet3/startSwingSet3.sh that runs the Java process as the logged in user will look like this:

#!/bin/sh
#save user to temporary variable
USER=$1
#shift the arguments by one - the user
shift
#handle system events
trap : SIGTERM SIGINT
#run java with sudo 
sudo -u $USER /home/work/jdk/jdk/bin/java $@ &
#wait for java to exit or kill if signaled 
JAVA_PID=$!
wait $JAVA_PID
if [[ $? -gt 128 ]]
then
    kill $JAVA_PID
fi

JavaFX

If you want to run your JavaFX application with Webswing, download the required JavaFX libraries here - https://mvnrepository.com/artifact/org.openjfx and add them to the javaFxClassPathEntries in app configuration. Webswing supports JavaFX versions 8, 11, 17 and 21. You can also use a JDK that has JavaFX libraries included. In such case set the configuration option javaFxEmbeddedInJdk to true, then you don't have to provide javaFxClassPathEntries or javaFxVersion.

JavaFX configuration