OiO.lk Blog java Problem with making a .jar with JavaFX and maven
java

Problem with making a .jar with JavaFX and maven


newbie here, I´m creating an App in IntelliJ with Maven, JDK 22, non-modular and using JavaFX 17.0.10, the problem is that when I generate my .jar with dependencies, it doesn’t open by double clicking it, instead I have to use java --module-path "C:\path\to\javafx-sdk-17.0.10\lib" --add-modules javafx.controls,javafx.fxml -jar BO-1.0-SNAPSHOT-jar-with-dependencies.jar in cmd.

When i run mvn clean package I recieve this error:
[WARNING] Failed to build parent project for org.openjfx:javafx-controls:jar:17.0.10 [WARNING] Failed to build parent project for org.openjfx:javafx-controls:jar:17.0.10 [WARNING] Failed to build parent project for org.openjfx:javafx-fxml:jar:17.0.10 [WARNING] Failed to build parent project for org.openjfx:javafx-fxml:jar:17.0.10 [WARNING] Failed to build parent project for org.openjfx:javafx-graphics:jar:17.0.10 [WARNING] Failed to build parent project for org.openjfx:javafx-graphics:jar:17.0.10 [WARNING] Failed to build parent project for org.openjfx:javafx-base:jar:17.0.10 [WARNING] Failed to build parent project for org.openjfx:javafx-base:jar:17.0.10

I need this app to be runned by double clicking it because i need to use it in multiple devices.

Here is my pom.xml:

`
4.0.0

<groupId>com.BO</groupId>
<artifactId>BO</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <junit.version>5.9.2</junit.version>
    <itext.version>8.0.5</itext.version>
    <javafx.version>17.0.10</javafx.version> <!-- Usa la versión más reciente -->
    <mainClass>main.Main</mainClass>
</properties>

<repositories>
    <repository>
        <id>maven-repo-itext</id>
        <url>https://repo.itextsupport.com/nexus/content/groups/public/</url>
    </repository>
    <repository>
        <id>openjfx</id>
        <url>https://openjfx.io/repo</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>net.sourceforge.jtds</groupId>
        <artifactId>jtds</artifactId>
        <version>1.3.1</version>
    </dependency>
    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <version>8.4.1.jre8</version>
    </dependency>
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>itextpdf</artifactId>
        <version>5.5.13.4</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>5.2.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>5.2.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml-schemas</artifactId>
        <version>4.1.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.xmlbeans</groupId>
        <artifactId>xmlbeans</artifactId>
        <version>5.1.1</version>
    </dependency>
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>kernel</artifactId>
        <version>8.0.5</version>
    </dependency>
    <dependency>
        <groupId>com.itextpdf</groupId>
        <artifactId>layout</artifactId>
        <version>8.0.5</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>${javafx.version}</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>${javafx.version}</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-graphics</artifactId>
        <version>${javafx.version}</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.11.0</version>
            <configuration>
                <source>22</source>
                <target>22</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>0.0.8</version>
            <executions>
                <execution>
                    <id>default-cli</id>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <mainClass>${mainClass}</mainClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.3.0</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>${mainClass}</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                        <mainClass>${mainClass}</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

`



You need to sign in to view this answers

Exit mobile version