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.

相关推荐
Java致死2 小时前
设计模式Java
java·开发语言·设计模式
源码方舟2 小时前
SpringBoot + Shiro + JWT 实现认证与授权完整方案实现
java·spring boot·后端
2401_cf5 小时前
为什么hadoop不用Java的序列化?
java·hadoop·eclipse
帮帮志5 小时前
idea整合maven环境配置
java·maven·intellij-idea
LuckyTHP5 小时前
java 使用zxing生成条形码(可自定义文字位置、边框样式)
java·开发语言·python
无声旅者8 小时前
深度解析 IDEA 集成 Continue 插件:提升开发效率的全流程指南
java·ide·ai·intellij-idea·ai编程·continue·openapi
Ryan-Joee8 小时前
Spring Boot三层架构设计模式
java·spring boot
Hygge-star8 小时前
【数据结构】二分查找5.12
java·数据结构·程序人生·算法·学习方法
dkmilk9 小时前
Tomcat发布websocket
java·websocket·tomcat
工一木子9 小时前
【Java项目脚手架系列】第七篇:Spring Boot + Redis项目脚手架
java·spring boot·redis