JavaFX Standalone mit Maven (Jlink)

Cromewell

Top Contributor
Hey zusammen, ich habe noch nicht viel mit Maven gemacht (eigentlich so gut wie gar nichts), und wollte gerade mein Javafx-Programm zu einer Standalone machen.
Dafür habe ich das Projekt modular gemacht usw. Nun will ich Jlink nutzen, um -s. Titel- zu erschaffen. Aber ich kriege einen Fehler in meiner modular-info.java:
java: package is empty or does not exist: org.openjfx
Die modular-info sieht wie folgt aus:
Java:
module Algebro {
    requires javafx.controls;
    requires javafx.fxml;
    requires java.desktop;

    opens org.openjfx to javafx.fxml;
    exports org.openjfx;
}

Meine pom ist:
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>Algebro</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>Algebro</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.release>11</maven.compiler.release>
        <javafx.version>13</javafx.version>
    </properties>

    <dependencies>
        <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>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <release>${maven.compiler.release}</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.3</version>
                <configuration>
                    <release>${maven.compiler.release}</release>
                    <jlinkImageName>Algebro</jlinkImageName>
                    <launcher>launcher</launcher>
                    <mainClass>MainApp</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

    
</project>

Hat jemand eine Ahnung, wie ich das lösen kann? Habe online nichts dazu entecken können und die openjfx dependencies hat er eigentlich eingebunden. Hoffe, ich habe alles bereitgestellt.

Vielen Dank für alle Mühen und angenehmen Samstag :)
 

Cromewell

Top Contributor
Ja, für mein code nutze ich ja auch import javafx..., aber für Maven muss man das anscheinend(?) so machen. Zumindest wurde es im Beispiel dort (hier bzw. unter runtime images) so gemacht, wie ich es dann übernommen habe.

Edit: Siehe auch hier.
 

mrBrown

Super-Moderator
Mitarbeiter
Das ist die groupID für die Maven-Artefakte, das Package ist aber was anderes :)

Lass die beiden letzten beiden Zeilen in deiner module-info mal weg
 

Cromewell

Top Contributor
Das ist die groupID für die Maven-Artefakte, das Package ist aber was anderes :)

Lass die beiden letzten beiden Zeilen in deiner module-info mal weg
Ups, da bin ich wohl etwas durch die Fehlermeldung "package not found" beeinflusst worden, entschuldige :D

Das habe ich tatsächlich schon versucht und dann hieß es: Failed to execute goal org.openjfx:javafx-maven-plugin:0.0.3:run (default-cli) on project Algebro: Error
 

mrBrown

Super-Moderator
Mitarbeiter
Ups, da bin ich wohl etwas durch die Fehlermeldung "package not found" beeinflusst worden, entschuldige :D
Die Fehlermeldung ist doch genau richtig, das Package gibt’s halt einfach nicht :p


Das habe ich tatsächlich schon versucht und dann hieß es: Failed to execute goal org.openjfx:javafx-maven-plugin:0.0.3:run (default-cli) on project Algebro: Error
Irgendwo findet sich doch sicherlich eine längere Fehlermeldung?
 

Cromewell

Top Contributor
Irgendwo findet sich doch sicherlich eine längere Fehlermeldung?
Du hast Recht:
Code:
[INFO] Compiling 5 source files to C:\Users\jrlac\IdeaProjects\Algebro\target\classes
Exception in Application constructor
Exception in thread "main" java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Unable to construct Application instance: class com.cromewell.algebro.MainApp
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:890)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: java.lang.IllegalAccessException: class com.sun.javafx.application.LauncherImpl (in module javafx.graphics) cannot access class com.cromewell.algebro.MainApp (in module Algebro) because module Algebro does not export com.cromewell.algebro to module javafx.graphics
    at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:376)
    at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:642)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:490)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:802)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    ... 1 more
[ERROR] Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
    at org.apache.commons.exec.DefaultExecutor.executeInternal (DefaultExecutor.java:404)
    at org.apache.commons.exec.DefaultExecutor.execute (DefaultExecutor.java:166)
    at org.openjfx.JavaFXBaseMojo.executeCommandLine (JavaFXBaseMojo.java:491)
    at org.openjfx.JavaFXBaseMojo.executeCommandLine (JavaFXBaseMojo.java:453)
    at org.openjfx.JavaFXRunMojo.execute (JavaFXRunMojo.java:97)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:567)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:47)
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
    at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:404)
    at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
    at org.openjfx.JavaFXBaseMojo.executeCommandLine(JavaFXBaseMojo.java:491)
    at org.openjfx.JavaFXBaseMojo.executeCommandLine(JavaFXBaseMojo.java:453)
    at org.openjfx.JavaFXRunMojo.execute(JavaFXRunMojo.java:97)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
Also muss ich anscheinend noch in der module-info module Algebro does not export com.cromewell.algebro to module javafx.graphics das hier passend exporten?!
 

Cromewell

Top Contributor
Super :D Habe es ergänzt und musste gerade noch die entsprechenden Dateien in den resources folder packen - total verpennt :D - und jetzt läuft es wie geschmiert!

Herzlichen Dank, @mrBrown ;p

Edit: P.S: mich wundert nur, dass es in dem Bsp. mit dem org.openjfx und so weiter war 🤔
 

Cromewell

Top Contributor
Ich möchte noch ergänzen, falls jemand in den gleichen Fehler rennt, wie ich und nach dem jlinken die Dateien aus dem resources folder nicht mehr gefunden werden - spich npe werfen -, dann schreibt open vor module. Also meine module-info sieht nun so aus:
Java:
open module Algebro {
    requires javafx.controls;
    requires javafx.fxml;
    requires java.desktop;

    exports com.cromewell.algebro;
}
und es funktioniert super. Ich hatte nichts online zu dieser Art Fehler gefunden, daher möchte ich das hier noch "verewigen".

Gruß

Cromewell
 

Ähnliche Java Themen

Neue Themen


Oben