1

Let me start off by saying this question is very similar to this one:

JavaFX Export and VM arguments

I've seen this question and it has helped me a lot further. However, I am quite new to Maven. I'm trying to export my maven project, which uses both JavaFX and JMTP, to an executeable jar file. However, after running mvn clean package, running the jar file (with dependecies) gives the following error:

Error: JavaFX runtime components are missing, and are required to run this application

This is my pom.xml file:

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.example</groupId>
    <artifactId>TestMavenFX</artifactId>
    <version>1.0-SNAPSHOT</version>
    <repositories>
        <repository>
            <id>in-project</id>
            <name>JMTP-in-project</name>
            <url>file://${project.basedir}\libs</url>
            <layout>default</layout>
        </repository>
    </repositories>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics </artifactId>
            <version>14</version>
            <classifier>win</classifier>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>14</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml </artifactId>
            <version>14</version>
            <classifier>win</classifier>
        </dependency>
        <dependency>
            <groupId>jmtp</groupId>
            <artifactId>jmtp-sdk</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <resources>
            <resource>
                <directory>src</directory>
                <excludes>
                    <exclude>*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>12</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.1</version>
                <configuration>
                    <mainClass>org.example.App</mainClass>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <mainClass>main.java.org.example.App</mainClass>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>
                                main.java.org.example.App
                            </mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                    <execution>
                        <id>make-jar-with-dependencies</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <archive>
                                <manifest>
                                    <mainClass>main.java.org.example.App</mainClass>
                                </manifest>
                            </archive>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Is there anyone who could help with this? I would like to use this instead of a .bat file to run a command to actually run the JAR file, but I'm quite stuck.

Stxfie
  • 23
  • 2
  • Not Maven-specific, but... Related Q&As: [How to deploy a JavaFX 11 Desktop application with a JRE](https://stackoverflow.com/questions/53453212/), [JavaFX 11 : Create a jar file with Gradle](https://stackoverflow.com/questions/52569724/), [Maven Shade JavaFX runtime components are missing](https://stackoverflow.com/questions/52653836/), and [Package a non-modular JavaFX application](https://stackoverflow.com/questions/54063041/). – Slaw May 24 '20 at 23:16
  • Thank you! Using the information from these links i managed to get it working! – Stxfie May 25 '20 at 10:37

0 Answers0