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.

相关推荐
小马爱打代码10 分钟前
Java泛型:T、E、K、V、?
java
l***370911 分钟前
基于SpringBoot和Leaflet的行政区划地图掩膜效果实战
java·spring boot·后端
小坏讲微服务15 分钟前
Spring Boot 4.0 与 Spring Cloud Alibaba 2025 整合完整指南
java·spring boot·分布式·后端·spring cloud·微服务·架构
毕设源码-邱学长16 分钟前
【开题答辩全过程】以 基于Spring Boot的酒店管理系统为例,包含答辩的问题和答案
java·spring boot·后端
晨晖225 分钟前
MyBatisPlus的条件构造器
java·数据库·windows
有味道的男人28 分钟前
速卖通商品详情接口(速卖通API系列)
java·大数据·数据库
一只小透明啊啊啊啊29 分钟前
垃圾回收算法有哪些
java·jvm
DanB2431 分钟前
Java(网络编程)
java·网络·php
5***846435 分钟前
Spring全家桶简介
java·后端·spring