JavaFX Maven Error
Javaprogrammer43
-
KX Posted messages 19031 Status Modérateur -
KX Posted messages 19031 Status Modérateur -
Hello,
I created a Maven project with my IDE (IntelliJ IDEA),
and when I run the project, I get this error:
Here is my pom.xml file:
Here is my fxml file:
And my Java class:
Thank you in advance for your response,
Javaprogrammer43
I created a Maven project with my IDE (IntelliJ IDEA),
and when I run the project, I get this error:
Error: JavaFX runtime components are missing, and are required to run this application
Here is my pom.xml file:
<?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>org.JonathanSoftware</groupId> <artifactId>presentation</artifactId> <version>1.0-SNAPSHOT</version> <name>presentation</name> <!-- FIXME change it to the project's website --> <url>https://github.com/Jonathan-Software</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-controls</artifactId> <version>15.0.1</version> </dependency> <dependency> <groupId>org.openjfx</groupId> <artifactId>javafx-fxml</artifactId> <version>16-ea+6</version> </dependency> </dependencies> <build> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <plugins> <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.1.0</version> </plugin> <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> </plugin> <plugin> <artifactId>maven-jar-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.5.2</version> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> </plugin> <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --> <plugin> <artifactId>maven-site-plugin</artifactId> <version>3.7.1</version> </plugin> <plugin> <artifactId>maven-project-info-reports-plugin</artifactId> <version>3.0.0</version> </plugin> <plugin> <groupId>org.openjfx</groupId> <artifactId>javafx-maven-plugin</artifactId> <version>0.0.5</version> <configuration> <mainClass>HelloFX</mainClass> </configuration> </plugin> </plugins> </pluginManagement> </build> </project>
Here is my fxml file:
<?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.control.Button?> <?import javafx.scene.control.Menu?> <?import javafx.scene.control.MenuBar?> <?import javafx.scene.control.MenuItem?> <?import javafx.scene.control.Separator?> <?import javafx.scene.control.SeparatorMenuItem?> <?import javafx.scene.control.ToolBar?> <?import javafx.scene.image.Image?> <?import javafx.scene.image.ImageView?> <?import javafx.scene.layout.AnchorPane?> <AnchorPane prefHeight="400.0" prefWidth="668.0" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.JonathanSoftware.presentation.controller.MainController"> <children> <ImageView fitHeight="342.0" fitWidth="448.0" layoutX="194.0" layoutY="88.0" pickOnBounds="true" preserveRatio="true"> <image> <Image url="@../ressources/logo_cloudpostman.png" /> </image></ImageView> <MenuBar layoutY="2.0" prefHeight="25.0" prefWidth="852.0"> <menus> <Menu mnemonicParsing="false" text="File"> <items> <MenuItem mnemonicParsing="false" text="About Cloud Postman" /> <SeparatorMenuItem mnemonicParsing="false" /> <MenuItem mnemonicParsing="false" text="Settings" /> <MenuItem mnemonicParsing="false" text="Open messages box" /> <MenuItem mnemonicParsing="false" text="Write new message" /> <MenuItem mnemonicParsing="false" onAction="#exit" text="Exit" /> </items> </Menu> <Menu mnemonicParsing="false" text="Edit"> <items> <MenuItem mnemonicParsing="false" text="Copy" /> <MenuItem mnemonicParsing="false" text="Paste" /> <MenuItem mnemonicParsing="false" text="Delete" /> <MenuItem mnemonicParsing="false" text="Refresh" /> </items> </Menu> <Menu mnemonicParsing="false" text="Help"> <items> <MenuItem mnemonicParsing="false" text="Cloud Postman wiki" /> <MenuItem mnemonicParsing="false" text="Check for update" /> </items> </Menu> </menus> </MenuBar> <ToolBar layoutY="445.0" prefHeight="51.0" prefWidth="852.0"> <items> <Button mnemonicParsing="false" prefHeight="6.0" prefWidth="50.0"> <graphic> <ImageView fitHeight="30.0" fitWidth="37.0" pickOnBounds="true" preserveRatio="true"> <image> <Image url="@../ressources/new_message_icon.png" /> </image> </ImageView> </graphic> </Button> <Button mnemonicParsing="false" prefHeight="38.0" prefWidth="39.0"> <graphic> <ImageView fitHeight="30.0" fitWidth="42.0" pickOnBounds="true" preserveRatio="true"> <image> <Image url="@../ressources/message_box_icon.png" /> </image> </ImageView> </graphic> </Button> <Separator orientation="VERTICAL" prefHeight="0.0" prefWidth="9.0" /> <Button mnemonicParsing="false" prefHeight="38.0" prefWidth="47.0"> <graphic> <ImageView fitHeight="78.0" fitWidth="25.0" pickOnBounds="true" preserveRatio="true"> <image> <Image url="@../ressources/Help_icon.png" /> </image> </ImageView> </graphic> </Button> <Button mnemonicParsing="false" prefHeight="38.0" prefWidth="54.0"> <graphic> <ImageView fitHeight="30.0" fitWidth="43.0" pickOnBounds="true" preserveRatio="true"> <image> <Image url="@../ressources/settings_icon.png" /> </image> </ImageView> </graphic> </Button> </items> </ToolBar> </children> </AnchorPane>
And my Java class:
package org.JonathanSoftware.presentation; import javafx.application.Application; import javafx.stage.Stage; public class ViewController extends Application { public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage primaryStage) { primaryStage.show(); } } Thank you in advance for your response,
Javaprogrammer43
1 réponse
Hello,
You won't be able to use JavaFX 15 while coding in Java 7. In the JavaFX 15 documentation, it is specified to use either Java 11 (the latest LTS version) or Java 15 (the latest non-LTS version).
In the Maven section of the documentation, you will find an archetype example to generate a Java FX project with Maven (I just tested it with a JDK 11 configured in JAVA_HOME)
--
Trust does not exclude control.
You won't be able to use JavaFX 15 while coding in Java 7. In the JavaFX 15 documentation, it is specified to use either Java 11 (the latest LTS version) or Java 15 (the latest non-LTS version).
In the Maven section of the documentation, you will find an archetype example to generate a Java FX project with Maven (I just tested it with a JDK 11 configured in JAVA_HOME)
mvn archetype:generate -DarchetypeGroupId=org.openjfx -DarchetypeArtifactId=javafx-archetype-simple -DarchetypeVersion=0.0.3 -DgroupId=org.openjfx -DartifactId=sample -Dversion=1.0.0 -Djavafx-version=15.0.1 cd sample mvn clean javafx:run
--
Trust does not exclude control.
However, I advise you to start the configuration from scratch using the archetype as I indicated to ensure that your configuration works well - including on IntelliJ - before you start modifying your project.
Because right now, with the little code you've shown us, there are already quite a few mistakes, for example, the inconsistency between your main class ViewController and the configuration
It smells like copy-pasting from different codes on the internet that have nothing to do with each other and may not even be related to the same versions of JavaFX (which was just starting out back in the days of Java 7 and has changed a lot since).
Once the project configuration is stable, you'll be sure that any bug will only be related to your code.
In the archetypes, there is also one that uses fxml; maybe that's the one you should test:
You'll see that the generated pom.xml is much simpler than the one you had.
Note: To build an IntelliJ project from a pom.xml, you can use the command which will generate the .iml, .ipr, and .iws files for your project.