Run HelloWorld using Maven(JavaFX)

简介: 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 Maven
使用IDEA创建基于maven的javaFX项目并使用Artifacts打包成jar
使用IDEA创建基于maven的javaFX项目并使用Artifacts打包成jar
239 0
使用IDEA创建基于maven的javaFX项目并使用Artifacts打包成jar
|
Java Maven
使用IDEA创建基于maven的javaFX项目并使用Artifacts打包成jar
使用IDEA创建基于maven的javaFX项目并使用Artifacts打包成jar
310 0
使用IDEA创建基于maven的javaFX项目并使用Artifacts打包成jar
|
Java
Idea+maven-jar-plugin构建JavaFX可执行jar包
Idea+maven-jar-plugin构建JavaFX可执行jar包
42 0
Idea+maven-jar-plugin构建JavaFX可执行jar包
|
Java Maven
使用IDEA创建基于maven的javaFX项目并使用Artifacts打包成jar
使用IDEA创建基于maven的javaFX项目并使用Artifacts打包成jar
使用IDEA创建基于maven的javaFX项目并使用Artifacts打包成jar
|
Java Maven
使用IDEA创建基于maven的javaFX项目并使用Artifacts打包成jar
使用IDEA创建基于maven的javaFX项目并使用Artifacts打包成jar
402 0
使用IDEA创建基于maven的javaFX项目并使用Artifacts打包成jar
|
Java Maven
SpringBoot_Exception_02_Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.6.RELEASE:run
一、现象 上一个异常解决之后,出现了这个异常: [WARNING] The requested profile "pom.xml" could not be activated because it does not exist.
4516 0
|
Java Maven
eclipse-->run as --> maven test 中文乱码
其有一个配置参数forkMode,默认为once,即表示每次运行test时,新建一个JVM进程运行所有test. 这可能会导致乱码问题.首先将forkMode设置为never,即不新建.再运行mvn test,全部OK了.
1463 0
|
Web App开发 XML Java
maven pom jetty run
  构建一个 maven jetty 项目  demo下载   1. 配置 jetty 插件在pom中 4.0.0 com.curiousby.cn MavenJettyRunDemo 0.
982 0
|
14天前
|
Java Apache Maven
Maven 项目文档
在`C:/MVN/consumerBanking`中创建Maven Java项目,使用命令`mvn archetype:generate`生成基础结构。确保`pom.xml`包含`maven-site-plugin`和`maven-project-info-reports-plugin`,版本至少为3.3和2.7,以避免`NoClassDefFoundError`。运行`mvn site`生成文档。