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 分钟前
基于SpringBoot实现的历史馆藏系统设计与实现【源码+文档】
java·spring boot·后端
毕设源码-赖学姐18 分钟前
【开题答辩全过程】以 高校教学资源共享系统的设计与实现为例,包含答辩的问题和答案
java·eclipse
辣机小司1 小时前
【软件设计师】自编思维导图和学习资料分享(中级已过)
java·c++·软考·软件设计师
爱笑的眼睛111 小时前
深入解析Matplotlib Axes API:构建复杂可视化架构的核心
java·人工智能·python·ai
乐观甜甜圈1 小时前
JDK8 中线程实现方法与底层逻辑详解
java
尤物程序猿1 小时前
Java如何不建表完成各种复杂的映射关系(鉴权概念、区域概念、通用概念)
java·开发语言
cike_y2 小时前
JSP内置对象及作用域&双亲委派机制
java·前端·网络安全·jsp·安全开发
也许是_2 小时前
大模型应用技术之 Spring AI 2.0 变更说明
java·人工智能·spring
xunyan62342 小时前
面向对象(下)-内部类的分类
java·学习
巴拉巴拉~~2 小时前
KMP 算法通用进度条组件:KmpProgressWidget 多维度 + 匹配进度联动 + 平滑动画
java·服务器·前端