JavaFX Application with Maven in Eclipse

2019-03-27 17:09发布

I want to ask if there is any method to add JavaFX into Maven Archetype list in Eclipse or any plugin to use Maven to build JavaFX Application.

3条回答
来,给爷笑一个
2楼-- · 2019-03-27 17:14

There is the javafx-maven-plugin which is available for maven.

When developing with Java 8 you just put that plugin as some build-plugin, without further dependencies.

<plugin>
    <groupId>com.zenjava</groupId>
    <artifactId>javafx-maven-plugin</artifactId>
    <version>8.8.3</version>
    <configuration>
        <mainClass>your.main.class.which.extends.javafx.Application</mainClass>
    </configuration>
</plugin>

Calling mvn jfx:jar creates your javafx-application-jar inside target/jfx/app/yourapp-jfx.jar, or even creates native launcher (like EXE-file) when calling mvn jfx:native.

Disclaimer: I'm the maintainer of the javafx-maven-plugin.

查看更多
做自己的国王
3楼-- · 2019-03-27 17:19

The only thing I add to my pom.xml in order to build JavaFX Application is this dependency :

<dependency>
        <groupId>com.oracle</groupId>
        <artifactId>javafx</artifactId>
        <version>2.2</version>
        <systemPath>${java.home}/lib/ext/jfxrt.jar</systemPath>
        <scope>system</scope>
</dependency>

It is simply fetching the javafx jar in my Java8 JRE to add it to the project. Then I use the maven-assembly-plugin to build the jar with dependencies.

Hope it helps.

查看更多
Juvenile、少年°
4楼-- · 2019-03-27 17:33

just do as a common Java application because JavaFX version jumped to 8.0. Supports for JavaFX are built-in.

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.6.0</version>
            <executions>
                <execution>
                    <id>run application</id>
                    <phase>package</phase>
                    <goals>
                        <goal>java</goal>
                    </goals>
                    <configuration>
                        <mainClass>cn.keepfight.intro.FXParamApp</mainClass>
                        <arguments>
                            <!--<argument>-Dsun.java2d.opengl=true</argument>-->
                        </arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>
查看更多
登录 后发表回答