JavaFX Application with Maven in Eclipse

前端 未结 5 1529
逝去的感伤
逝去的感伤 2021-01-02 01:41

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.

相关标签:
5条回答
  • 2021-01-02 02:04

    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.
    0 讨论(0)
  • 2021-01-02 02:08

    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>
    
    0 讨论(0)
  • 2021-01-02 02:10

    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.

    0 讨论(0)
  • 2021-01-02 02:20

    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.

    0 讨论(0)
  • 2021-01-02 02:23
    <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>
    
    0 讨论(0)
提交回复
热议问题