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.

相关推荐
怀旧诚子1 小时前
timeshift之Fedora43设置,已在VM虚拟机验证,待真机验证。
java·服务器·数据库
1104.北光c°1 小时前
滑动窗口HotKey探测机制:让你的缓存TTL更智能
java·开发语言·笔记·程序人生·算法·滑动窗口·hotkey
云原生指北4 小时前
GitHub Copilot SDK 入门:五分钟构建你的第一个 AI Agent
java
Leinwin8 小时前
OpenClaw 多 Agent 协作框架的并发限制与企业化规避方案痛点直击
java·运维·数据库
薛定谔的悦8 小时前
MQTT通信协议业务层实现的完整开发流程
java·后端·mqtt·struts
enjoy嚣士9 小时前
springboot之Exel工具类
java·spring boot·后端·easyexcel·excel工具类
罗超驿9 小时前
独立实现双向链表_LinkedList
java·数据结构·链表·linkedlist
盐水冰10 小时前
【烘焙坊项目】后端搭建(12) - 订单状态定时处理,来单提醒和顾客催单
java·后端·学习
凸头10 小时前
CompletableFuture 与 Future 对比与实战示例
java·开发语言
wuqingshun31415910 小时前
线程安全需要保证几个基本特征
java·开发语言·jvm