JavaFX Application with Maven in Eclipse
Asked Answered
O

5

12

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.

Outfit answered 21/12, 2015 at 3:1 Comment(0)
J
17

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.

Jungjungfrau answered 21/12, 2015 at 14:26 Comment(4)
It's a bit outdated and not fully finished, but you can use our configuration-creation website: javafx-maven-plugin.github.ioJungjungfrau
It's for maven only or we can integrate it with eclipse. I mean running like application on eclipse.Outfit
That maven-plugin just wrapps the commandline-calls for javapackager. You should be able to create your own run-command to execute java -jar target/jfx/app/yourapp-jfx.jar. Running javafx-applications is different, because of the possabilities for JVM-arguments, so just calling the main-method is not how javafx-applications are working.Jungjungfrau
These answers are old. The correct (current) answer is available here: openjfx.io/openjfx-docs/#mavenGreg
P
8

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.

Pyrography answered 21/12, 2015 at 11:2 Comment(0)
K
2

This answer is copied from the documentation at https://openjfx.io/openjfx-docs/#maven. More detailed information (including a full sample pom.xml reference) is available at the link provided.

The pom uses the JavaFX Maven plugin:

<plugins>
    <plugin>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-maven-plugin</artifactId>
        <version>0.0.3</version>
        <configuration>
            <mainClass>HelloFX</mainClass>
        </configuration>
    </plugin>
</plugins>

Add the maven dependencies:

<dependencies>
  <dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>13</version>
  </dependency>
</dependencies>

Run the application (e.g. based on the HelloFX.java from the referred sample):

mvn clean javafx:run

Note regarding other outdated answers

  1. Previous (highly-voted) answers which reference the com.zenjava javafx-maven-plugin are outdated, as that plugin is not coded to work with recent JavaFX versions. For Java versions 10+, the org.openjfx javafx-maven-plugin should be used.
  2. Also, for Java 10+, answers which reference only the assembly plugin and state that JavaFX is included in the JDK, are also outdated. JavaFX is no longer bundled in recent JDK releases, instead it is available as a separate SDK from openjfx.io or as a set of library dependencies from the maven central repository.
Koziara answered 30/12, 2019 at 9:32 Comment(0)
C
1
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>3.2.0</version>
    <executions>
        <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <archive>
            <manifest>
                <mainClass>com.MainClass</mainClass>
            </manifest>
        </archive>
    </configuration>
</plugin>
Cai answered 30/12, 2019 at 8:24 Comment(0)
M
0

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>
Mandimandible answered 10/5, 2017 at 5:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.