0

I have a JavaFX application which I can compile and create a jar file with the following maven configuration inside IntelliJ idea:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.10.1</version>
            <configuration>
                <source>18</source>
                <target>18</target>
            </configuration>
        </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>net.golbarg.nahjolfasahe/net.golbarg.nahjolfasahe.MainApp</mainClass>
                        <launcher>app</launcher>
                        <compress>2</compress>
                        <jlinkZipName>app</jlinkZipName>
                        <jlinkImageName>app</jlinkImageName>
                        <noManPages>true</noManPages>
                        <stripDebug>true</stripDebug>
                        <noHeaderFiles>true</noHeaderFiles>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>
                            ${project.build.directory}/libs
                        </outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.3.0</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>libs/</classpathPrefix>
                        <mainClass>
                            net.golbarg.nahjolfasahe.MainApp
                        </mainClass>
                    </manifest>
                </archive>
                <finalName>setup</finalName>
            </configuration>
        </plugin>
    </plugins>
</build>

more details

But for running this jar file I had to run it as below:

"C:\Program Files\Java\jdk-18.0.1.1\bin\java.exe" --module-path "C:\Program Files\Java\javafx\javafx-sdk-19\lib" --add-modules javafx.controls,javafx.fxml,javafx.swing -Dfile.encoding=windows-1252 -jar C:\work\system\NahjolFasahe\target\setup.jar

adding --module-path and --add-modules parameters before running the jar file.

VM options Image

How can I simplify and add this settings either by editing the maven file or including it in the Manifest file of the builder jar file?

I want to make my jar file openable just by double clicking and include these configuration inside my jar file.

Mustafa Poya
  • 2,615
  • 5
  • 22
  • 36
  • 2
    If you can do `mvn clean javafx:jlink`, you should then be able to run as `app/bin/java` in the `target`directory. – trashgod Dec 11 '22 at 14:28
  • The official Java specs haven't been extended to support a fat modularized jar. Have you considered https://maven.apache.org/plugins/maven-jlink-plugin/ to create a distribution? – Robert Scholte Dec 11 '22 at 14:31
  • 1
    It looks like you already have the [`javafx-maven-plugin`](https://github.com/openjfx/javafx-maven-plugin) options for [`jlink`](https://github.com/openjfx/javafx-maven-plugin#javafxjlink-options). – trashgod Dec 11 '22 at 14:38
  • @trashgod, I tried this: `mvn clean javafx:jlink` and this cause another issue which building by `jlink` How can I include the dependencies – Mustafa Poya Dec 11 '22 at 16:36
  • It appear to depend on the dependencies: more [here](https://stackoverflow.com/search?q=%5Bjavafx%5D+jlink+include+dependencies). – trashgod Dec 11 '22 at 19:40
  • For `jlink` to work, you must also have a `module-info.java` with *no [automatic modules](https://stackoverflow.com/questions/46741907/what-is-an-automatic-module)* and requiring all of the modules you need (VM arguments for modules are unnecessary). Information on creating modular JavaFX apps using a build tool like Maven is at [openjfx.io](https://openjfx.io/). Information on generating runtime images from such a project using jlink is also at openjfx.io and in the [javafx-maven-plugin documentation](https://github.com/openjfx/javafx-maven-plugin). – jewelsea Dec 12 '22 at 07:13

0 Answers0