[英]Compiling JavaFX jar with all dependencies using Maven
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>
在我的<plugins>
块中,我具有以下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
但是,除了包含MANIFEST.MF
的META-INF
文件夹之外,编译到我的target
目录的.jar完全为空。
我到底在做什么错? Maven给我以下日志消息[INFO] Adding 'deploy' directory to Mojo classpath: /Users/adonis/school/recommendify/src/main/deploy
。 什么是Mojo? 我是否应该使用deploy
包来存放我的.java文件? 之前我遇到一个问题,即使用Intellij的运行应用程序功能时,我的fxml views
包没有被编译到类输出目录中,经过一番研究,我推断我的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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.