Protection for JavaFX applications

JavaFX can be enabled for both regular Java applications and Spring Boot desktop applications. The lightweight runtime of P4JX does not include JavaFX by default, and it must be explicitly enabled or via compatibility suggestions during packaging.

1. GUI operations

  1. For regular JavaFX applications, select Java Application on the application type page; for JavaFX desktop applications using a Spring container, select Spring Boot. Library Encryption only generates a protected archive and cannot replace the actual JavaFX application packaging.

    Select Java Application or Spring Boot

  2. Select the input JAR, The included Java version, and target platform, then choose between simple mode or advanced mode. JavaFX assets are obtained separately for each target Java version and platform; multi-platform tasks will produce independent output packages.

    Select input, Java version, target platform, and mode

  3. In simple mode, if the compatibility scan detects references to javafx.* or JavaFX dependencies, it will explain the reasons for the adjustments in the scan results and automatically enable JavaFX. If javafx.scene.web is detected, WebView will also be included. The scan is a static heuristic analysis, so the JavaFX summary should still be reviewed after going to the output page.

  4. In advanced mode, check Bundle JavaFX into the packaged runtime in the JavaFX runtime tab, then select a WebView strategy:

    • Auto: Automatically determined based on whether the application references javafx.scene.web.
    • Include: Forces the inclusion of WebView (fx-webkit);
    • Exclude: Forces the exclusion of WebView.

    The entry point for regular Java applications is as follows:

    Select the JavaFX runtime from the advanced parameters of a regular Java application

    Spring Boot desktop applications use the same tab name:

    Select the JavaFX runtime under Advanced Parameters in Spring Boot

  5. After selecting the output directory, verify that JavaFX is shown as built-in in the parameter summary and that the WebView status matches expectations, then click Run protection. After generation, use the startup script within the package to verify the window, FXML, CSS/image resources, and WebView on each target platform.

The WebView assets are approximately 40 MB; you can choose Exclude to reduce the package size when it is not in use. For the meanings of other settings in the advanced interface, see Protector4J Advanced Mode Settings and Spring Boot Configuration.

2. CLI available online

p4j javaapp fx-app.jar dist --javafx

Spring Boot JavaFX:

p4j springboot fx-boot.jar dist --javafx

Forcing the inclusion or exclusion of WebView:

--javafx-webview
--no-javafx-webview

The tool retrieves the corresponding materials from public download sites in the current region based on the target Java training environment and platform. Neither JavaFX downloads nor VLX JRE downloads require the cloud storage key to be sent to the client.

3. Offline materials

CLI supports local directories:

p4j javaapp fx-app.jar dist --javafx /opt/p4jx-fx

The directory can contain:

  • fx-core.tar.gz along with the optional fx-webkit.tar.gz; or
  • A JavaFX file tree that is expanded with lib/ as the root.

The GUI does not provide an option to select a local JavaFX directory; use the CLI for offline scenarios.

4. FXML

If the application uses FXMLLoader, the compatibility scan will recommend enabling the scanner ZIP overlay:

p4j javaapp fx-app.jar dist --javafx --zip-overlay scanner

FXML-related resources, controller signatures, and framework scanning require actual startup testing on the target platform.

5. Java 8 and Java 11+

  • Java 8 uses the jfxrt.jar/extension directory model, and script generation usually does not require module parameters.
  • Java 11+ uses modular JavaFX JARs, and script generation automatically sets a dedicated module path along with --add-modules.

Always use the generated run.sh, run.command, or run.bat; do not treat the entire vlxjre/lib as the module path on your own.

6. Automatic boundary detection

The detector scans the application’s own class references and determines JavaFX based on the names of dependent JAR files. It does not deeply scan the bytecode of all third-party dependencies to avoid misclassifying optional JavaFX integrations as actually in use.

If JavaFX is shaded into a dependency whose name does not reveal its nature, automatic scanning may result in missed detections; in such cases, explicitly use --javafx.

  • Whether JavaFX Application subclasses, FXML Controllers, and property models should be protected should be determined based on actual testing results for the target Java version.
  • Bridge classes accessed directly via JNI/native should remain as regular classes.
  • First use simple mode or --compat-scan, then conduct regression tests for window opening, FXML loading, CSS/image resources, WebView, and platform native libraries.