如何使用Maven项目在JavaFX中生成可执行jar [英] How to generate executable jar in JavaFX with maven project
本文介绍了如何使用Maven项目在JavaFX中生成可执行jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法运行生成的jar文件.这是我的错误输出:
I can't run generated jar file. Here's my error output:
myapp.jar中没有主清单属性
no main manifest attribute, in myapp.jar
这是我的pom.xml文件:
Here is my pom.xml file:
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.4</version>
<configuration>
<mainClass>Main</mainClass>
<executable>/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.2.jdk/Contents/Home/bin</executable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
</plugin>
<!-- fat jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven.shade.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
伙计们,帮帮我!该如何解决?
Guys, help me! how to solve that issue?
推荐答案
Maven阴影插件通过以下配置为我工作:
Maven shade plugin worked for me with this configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
只需将 Main 替换为您的主类.
要创建胖子罐,您需要调用maven package命令:
Just replace Main with your main class.
To create the fat jar you need to call maven package command:
mvn package
这篇关于如何使用Maven项目在JavaFX中生成可执行jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文