0

I use "mvn clean package" command to get an jar file.

But when I call it I get the following error:

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

I execute it with the following command:

java -jar target/mavenproject1-1.0-SNAPSHOT.jar

Please help me to get it to work. How can I integrate the javafx dependencies that no separate installation of javafx is required?

POM.XML

<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>com.mycompany</groupId>
    <artifactId>mavenproject1</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <mainClass>com.mycompany.mavenproject1.App</mainClass>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>13</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>13</version>
        </dependency>
        <dependency>
            <groupId>com.yworks</groupId>
            <artifactId>yguard</artifactId>
            <version>3.0.0</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.8</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <id>obfuscate</id>
                        <configuration>
                            <tasks>
                                <property name="runtime_classpath" refid="maven.runtime.classpath"/>
                                <taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" classpath="${runtime_classpath}"/>
                                <yguard>
                                    <!-- see the yGuard task documentation for information about the <yguard> element-->
                                    <inoutpair in="${project.build.directory}/${project.build.finalName}.jar" out="${project.build.directory}/${project.build.finalName}_obfuscated.jar" />

                                    <shrink logfile="${project.build.directory}/yshrink.log.xml">
                                        <keep>
                                            <!-- main method -->
                                            <method name="void main(java.lang.String[])" class="${mainClass}" />
                                        </keep>
                                    </shrink>

                                    <rename mainclass="${mainClass}" logfile="${project.build.directory}/yguard.log.xml">
                                        <property name="error-checking" value="pedantic"/>
                                    </rename>
                                </yguard>
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.4</version>
                <configuration>
                    <mainClass>${mainClass}</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <!-- Default configuration for running -->
                        <!-- Usage: mvn clean javafx:run -->
                        <id>default-cli</id>
                    </execution>
                    <execution>
                        <!-- Configuration for manual attach debugging -->
                        <!-- Usage: mvn clean javafx:run@debug -->
                        <id>debug</id>
                        <configuration>
                            <options>
                                <option>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:8000</option>
                            </options>
                        </configuration>
                    </execution>
                    <execution>
                        <!-- Configuration for automatic IDE debugging -->
                        <id>ide-debug</id>
                        <configuration>
                            <options>
                                <option>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</option>
                            </options>
                        </configuration>
                    </execution>
                    <execution>
                        <!-- Configuration for automatic IDE profiling -->
                        <id>ide-profile</id>
                        <configuration>
                            <options>
                                <option>${profiler.jvmargs.arg1}</option>
                                <option>${profiler.jvmargs.arg2}</option>
                                <option>${profiler.jvmargs.arg3}</option>
                                <option>${profiler.jvmargs.arg4}</option>
                                <option>${profiler.jvmargs.arg5}</option>
                            </options>
                        </configuration>
                    </execution>
                </executions>
            </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>${mainClass}</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
</project>
sm-a
  • 65
  • 3
  • Are you having trouble creating a manifest, or have you tried `conservemanifest`? – trashgod Jan 30 '22 at 17:30
  • @trashgod I am not sure what I am doing wrong. Can you please explain what I am doing wrong. I used Apache Netbeans with the project type "JavaFX FXML" to create and I have only made the pom additions or do I need to adjust something elsewhere? – sm-a Jan 30 '22 at 22:46
  • I'm guessing you either don't have a manifest or that it's getting obfuscated; I've not used `yguard`, but I see it has a `conservemanifest` attribute that might help. – trashgod Jan 31 '22 at 00:45
  • @trashgod Ok. I use yguard later. When I delete yguard and I run the jar file I get an different error: "JavaFX runtime components are missing, and are required to run this application". I hope you can help. – sm-a Jan 31 '22 at 03:17
  • The duplicate addresses your shade issue. I don’t know yguard or if that will cause additional issues. If it does, you could ask a separate question just about that. If – jewelsea Jan 31 '22 at 06:46
  • Also see the [eden guide to the runtime component missing error](https://edencoding.com/runtime-components-error/). – jewelsea Jan 31 '22 at 06:47
  • Also consider `maven-jar-plugin`, seen [here](https://github.com/trashgod/modular/blob/master/pom.xml), for the manifest. – trashgod Jan 31 '22 at 14:18

0 Answers0