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.

相关推荐
Grey Zeng2 小时前
Java SE 25新增特性
java·jdk·jdk新特性·jdk25
雨白3 小时前
Java 线程通信基础:interrupt、wait 和 notifyAll 详解
android·java
架构师沉默7 小时前
设计多租户 SaaS 系统,如何做到数据隔离 & 资源配额?
java·后端·架构
Java中文社群9 小时前
重要:Java25正式发布(长期支持版)!
java·后端·面试
每天进步一点_JL10 小时前
JVM 类加载:双亲委派机制
java·后端
用户2986985301410 小时前
Java HTML 转 Word 完整指南
java·后端
渣哥11 小时前
原来公平锁和非公平锁差别这么大
java
渣哥11 小时前
99% 的人没搞懂:Semaphore 到底是干啥的?
java
J2K11 小时前
JDK都25了,你还没用过ZGC?那真得补补课了
java·jvm·后端
kfyty72511 小时前
不依赖第三方,不销毁重建,loveqq 框架如何原生实现动态线程池?
java·架构