【问题标题】:Compiling JavaFX jar with all dependencies using Maven使用 Maven 编译具有所有依赖项的 JavaFX jar
【发布时间】:2019-05-02 20:27:39
【问题描述】:

Java 和 Maven 新手。

我正在尝试配置我的应用程序,以便我可以通过 cmd 行生成一个 jar,其中包含我的所有依赖项。

据我所知,我正在正确设置我的 Pom 以使用此插件:https://github.com/javafx-maven-plugin/javafx-maven-plugin

这是我在 Pom 中的依赖项:

    <dependencies>
        <dependency>
            <groupId>se.michaelthelin.spotify</groupId>
            <artifactId>spotify-web-api-java</artifactId>
            <version>2.1.1</version>
        </dependency>

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

在我的 &lt;plugins&gt; 块中,我有以下 Maven 插件:

  • javafx-maven-plugin
  • maven-compiler-plugin
  • maven 组装插件

javafx-maven-plugin 的配置方式如下:

                <groupId>com.zenjava</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>8.8.3</version>
                <configuration>
                    <mainClass>recommendify.Main</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <id>create-jfxjar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>build-jar</goal>
                        </goals>
                    </execution>
                </executions>

另一个处理此问题的 SO 主题说要像这样配置maven-assembly-plugin(据我了解,这是打包所有依赖项的内容):

        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
            <execution>
                <id>create-executable</id>
                <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <outputDirectory>${test.pack.dir}</outputDirectory>
            <appendAssemblyId>false</appendAssemblyId>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
            <archive>
                <manifest>
                    <mainClass>recommendify.Main</mainClass>
                </manifest>
            </archive>
        </configuration>

使用这个 Maven 配置,我运行以下命令来编译 .jar:mvn clean compile jfx:build-jar

但是,编译到我的 target 目录的 .jar 除了包含 MANIFEST.MFMETA-INF 文件夹之外完全是空的。

我到底做错了什么? Maven 给了我以下日志消息[INFO] Adding 'deploy' directory to Mojo classpath: /Users/adonis/school/recommendify/src/main/deploy。什么是魔约?我应该使用deploy 包来存放我的.java 文件吗?我之前遇到了一个问题,当使用 Intellij 的运行应用程序功能时,我的 fxml views 包没有被编译到类输出目录,经过一番研究,我推断我的 fxml 应该存储在 resources/fxml 下而不是我的恰当地命名为views。这让我相信我需要一个“部署”目录/包。

任何帮助将不胜感激:)

【问题讨论】:

    标签: java maven javafx


    【解决方案1】:

    尝试使用 Maven Jar 插件。这是我在所有 JavaFX 项目中所拥有的:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.1.0</version>
        <configuration>
            <archive>
                <manifest>
                    <mainClass>Your.Main.Class.Here</mainClass>
                </manifest>
            </archive>
        </configuration>
    </plugin>
    

    【讨论】:

    • 那么我不会使用mvn jfx:build-jar 来编译,对吧?什么命令? mvn clean package?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多