'JavaFX: Unrecognized option: --add-exports javafx.base/com.sun.javafx.event=org.controlsfx.controls

I developed a JavaFX application and through JPackage I created the installation package. When I try to click on the * .exe startup file of my application I get the error:

Unrecognized option: --add-exports javafx.base/com.sun.javafx.event=org.controlsfx.controls
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Here is my configuration:

  1. S.O. Windows10

  2. java

    java version "17.0.2" 2022-01-18 LTS Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86) Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)

  3. Jpackage version 17.0.1

These are the steps to create the installation package:

  1. Create FAT Jar with Maven:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>17</source>
                <target>17</target>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>1.18.22</version>
                    </path>
                </annotationProcessorPaths>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>Launcher</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>com.merkury.Launcher</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id> <!-- this is used for inheritance merges -->
                    <phase>package</phase> <!-- bind to the packaging phase -->
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>0.0.8</version>
            <executions>
                <execution>
                    <!-- Default configuration for running with: mvn clean javafx:run -->
                    <id>default-cli</id>
                    <configuration>
                        <mainClass>com.merkury.Launcher</mainClass>
                        <options>
                            <option>--add-exports</option>
                            <option>javafx.base/com.sun.javafx.event=org.controlsfx.controls</option>
                        </options>
                        <launcher>app</launcher>
                        <jlinkZipName>app</jlinkZipName>
                        <jlinkImageName>app</jlinkImageName>
                        <noManPages>true</noManPages>
                        <stripDebug>true</stripDebug>
                        <noHeaderFiles>true</noHeaderFiles>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    
  2. Create a Custom Runtime Image

    jlink --output install/windows/merkury --module-path "D:\Program Files\javafx-jmods-17.0.2" --add-modules javafx.controls,javafx.fxml,java.sql,java.logging
    
  3. Launch Jpackage

    jpackage --input target --name Merkury --main-jar Mercury-1.0-SNAPSHOT-jar-with-dependencies.jar --main-class com.merkury.Launcher --description "Software gestionale per i medici del lavoro" --vendor "Nvsecurity.it" --icon install/assets/merkury.ico --dest install/output --app-version 1.0 --runtime-image install/windows/merkury --win-shortcut --win-dir-chooser --win-menu --win-menu-group "Nvsecurity Merkury" --type exe --java-options "'--add-exports javafx.base/com.sun.javafx.event=org.controlsfx.controls'" --win-console
    

In my application I need to use AutoCompletionBinding and as stated here I had to add the option for the VM as java-options of Jpackage:

--add-exports=javafx.base/com.sun.javafx.event=org.controlsfx.controls

Can anyone explain to me what is happening? Thank you

EDIT 05-03-22

Do you need both double and single quotes to supply the add-exports option to jpackage?

Yes As described Here

Perhaps try using JPackageScriptFX

I tried to package and deploy the indicated project. Adding the option

  --java-options "'--add-exports javafx.base/com.sun.javafx.event=org.controlsfx.controls'"^

doesn't work. Without it works.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source