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.

相关推荐
汤米粥6 分钟前
python学习——核心语法三
java·python·学习
basketball61615 分钟前
Kadane算法 C++实现
java·c++·算法
better_liang36 分钟前
每日Java面试场景题知识点之-如何设计分布式锁
java·redis·zookeeper·面试·分布式锁
战族狼魂37 分钟前
集 “自动飞行、智能识别、实时预警、勤务联动” 于一体的高速公路应急车道无人机检测系统方案
java·人工智能·大模型·无人机
一只鹿鹿鹿44 分钟前
信息化项目管理规范(参考Word文件)
java·大数据·运维·开发语言·数据库
Java小白笔记1 小时前
Linux 手动部署 Oracle JDK 17 完全指南
java·linux·oracle
夕除1 小时前
实战--2
java·spring boot·spring
Chase_______1 小时前
【Java杂项】final 关键字详解:变量、方法、类限制与引用可变性
java·开发语言·python
凤山老林1 小时前
DDD(领域驱动设计)在复杂业务系统中的落地指南
java·开发语言·数据库·ddd·领域驱动
JEECG低代码平台1 小时前
JimuChatBI — 首款免费开源的 Java 智能问数ChatBI平台,零成本接入,AI对话式智能分析
java·人工智能·开源·aigc·人工智能低代码