java - 使用 Maven 编译具有所有依赖项的 JavaFX jar

标签 java maven javafx

Java 和 Maven 新手。

我正在尝试配置我的应用程序,以便可以通过命令行生成一个 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>

在我的<plugins>我有以下 Maven 插件:

  • javafx-maven-插件
  • maven-编译器插件
  • 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除了 META-INF 之外,目录完全是空的包含 MANIFEST.MF 的文件夹.

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

任何帮助将非常感激:)

最佳答案

尝试使用 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>

关于java - 使用 Maven 编译具有所有依赖项的 JavaFX jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53561657/

相关文章:

java - 如何在 Java 中运行 Socket.IO 客户端-服务器

java - 数组计数不正确

java - 在 Maven 中生成源 jar 时排除包

unit-testing - 在 Jenkins 中构建子项目时单元测试结果未显示在 Sonar 中

java - Gradle包括JavaFX for Heroku

java - 生成 N x N 网格

java - 在 Spring 3.2 中禁用路径变量中的空格修剪

Java 格式化行以使列对齐

svn - Grails 插件 Maven 存储库

java - com.sun.javafx.robot.FXRobot 是专有的