Run HelloWorld using Maven(JavaFX)

If you want to develop JavaFX applications using Maven, you don't have to download the JavaFX SDK. Just specify the modules and the versions you want in the pom.xml, and the build system will download the required modules, including the native libraries for your platform.

Here is a pom.xml file which shows how to achieve this, included in this sample.

Alternatively, we have created JavaFX Maven Archetypes to quickly create Maven projects. A simple JavaFX project can be created by executing the following command:

复制代码
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=11

The pom uses the JavaFX Maven plugin:

复制代码
<plugins>
    <plugin>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-maven-plugin</artifactId>
        <version>0.0.1</version>
        <configuration>
            <mainClass>HelloFX</mainClass>
        </configuration>
    </plugin>
</plugins>

Add the maven dependencies:

复制代码
<dependencies>
  <dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>11</version>
  </dependency>
</dependencies>

Important : Note that transitive dependencies are automatically resolved (for instance, there is no need to add a dependency for the javafx.graphics module, since it is transitively resolved by the javafx.controls module). But if your application is using FXML, you will need to add a dependency for the javafx.fxml module as well.

Finally, run the application (e.g. based on the HelloFX.java from the referred sample):

复制代码
mvn clean javafx:run

**Note:**Make sure to set the JAVA_HOME environment variable to the correct JDK location.

相关推荐
code小毛孩16 分钟前
如何简单的并且又能大幅度降低任务队列的锁粒度、提高吞吐量?
java·jvm·数据库
你不是我我22 分钟前
【Java开发日记】请介绍类加载过程,什么是双亲委派模型?
java·开发语言
牢七30 分钟前
java10
java
阿挥的编程日记37 分钟前
基于SpringBoot的高校(学生综合)服务平台的设计与实现
java·spring boot·后端·spring·mybatis
小霞在敲代码39 分钟前
ArrayList - 数据结构 - 数组
java·索引
一个小白开发2 小时前
ip获取城市省份信息
java·tcp/ip
豆沙沙包?2 小时前
2025年--Lc170--H289. 生命游戏(矩阵)--Java版
java·游戏·矩阵
冬夜戏雪2 小时前
[学习日记][springboot 1-7][leetcode 6道]
java·开发语言·学习
讓丄帝愛伱2 小时前
idea 中 mapper.xml黄线警告怎么去掉
java·intellij-idea
桦说编程3 小时前
线程池拒绝策略避坑:谨慎使用抛弃策略,可能导致系统卡死
java·后端