gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:32:03 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com