Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX Application with Maven in Eclipse

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.

like image 812
Einsamer Avatar asked Dec 21 '15 03:12

Einsamer


People also ask

How do I create a JavaFX Maven project?

Create a Maven projectSelect File -> New -> Project -> Maven and enable Create from archetype . If the JavaFX archetype is not installed yet, select Add archetype... and set the groupId ( org. openjfx ), the artifactId ( javafx-maven-archetypes ), and the version ( 0.0. 6 ), and press OK.

Can you run JavaFX in Eclipse?

Now, we need to configure Eclipse to execute the JavaFX applications. There are two ways of Eclipse Configuration for this purpose. We can either export the JavaFX jar files to every Java project or install a new software which can support the JavaFX project creation directly.


2 Answers

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.
like image 170
jewelsea Avatar answered Sep 19 '22 19:09

jewelsea


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.

like image 24
FibreFoX Avatar answered Sep 20 '22 19:09

FibreFoX