0

I have created a program using javafx 17.0.2 and compiled it with maven into a jar. It is unable to be opened alone so I have to create a bat file and use the command "java --module-path "C:\Program Files\Java\javafx-sdk-17.0.2\lib" --add-modules=javafx.controls,javafx.fxml -jar BattleDisc_Matchmaker-1.0-SNAPSHOT.jar" to open it.

I want this program to be easy to use, as any program should be. Is there a way for me to wrap it with javafx so that it can be opened without any extra work by the user?

Here is my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>groupId</groupId>
<artifactId>BattleDisc_Matchmaker</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>
    <javafx.version>17</javafx.version>
    <javafx.maven.plugin.version>3.8.1</javafx.maven.plugin.version>
</properties>

<name>BattleDisc Matchmaker</name>

<parent>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx</artifactId>
    <version>17</version>
</parent>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <release>3.8.1</release>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>0.0.8</version>
            <configuration>
                <mainClass>Main</mainClass>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.4</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>Main</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>17</version>
    </dependency>
      <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-graphics</artifactId>
        <version>17</version>
        <classifier>win</classifier>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-graphics</artifactId>
        <version>17</version>
        <classifier>linux</classifier>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-graphics</artifactId>
        <version>17</version>
        <classifier>mac</classifier>
    </dependency>
</dependencies>

Javafx is already a dependency, which is why im so confused as to why it needs a special .bat to run.

If the user needs jre, thats of course fine because everyone has that. But JFX is a developer specific thing and I dont want to make every person that wants to use it have to download it then edit a bat file.

JoeProKill
  • 11
  • 1
  • "If the user needs jre, thats of course fine because everyone has that." -> having a compatible JRE for your application may be less common than you may suppose. – jewelsea Feb 02 '22 at 08:25
  • Your packaging commands only including cross-platform dependencies for the javafx-graphics module, that may be sufficient, but you might need cross-platform dependency specifiers for other modules. Also, if you want M1 support you should use 17.0.2 and have an additional classifier dependency for mac-aarch64. – jewelsea Feb 02 '22 at 08:32
  • The Maven packages for JavaFX 17 are broken, you should use 17.0.2+ (see the linked duplicate regarding JavaFX 17 and Maven for more info). – jewelsea Feb 02 '22 at 10:45

0 Answers0