Maven生成的jar文件中MANIFEST.MF中缺少Main-class头像 [英] Missing Main-Class attibute in MANIFEST.MF in Maven generated jar file
问题描述
我目前正在Eclipse(m2e-Plugin)中使用Maven进行实验,并试图构建和运行Hello World示例项目.但是,启动生成的jar时,没有任何反应.我检查了MANIFEST.MF,发现Main-Class属性丢失了.添加属性后,可以启动jar.
I am currently experimenting with Maven in Eclipse (m2e-Plugin) and tried to build and run the Hello World example project. However, when launching the generated jar, nothing happens. I checked the MANIFEST.MF and noticed that the Main-Class attribute was missing. After adding the attribute, the jar could be launched.
为什么Maven不添加此属性?
Why does Maven not add this attribute?
推荐答案
看看此链接: https://maven.apache.org/shared/maven-archiver /examples/classpath.html#aAdd 您可以在此处找到如何配置maven项目以运行特定的类.您必须添加定义了mainClass的maven-jar-plugin配置.
Have a look at this link: https://maven.apache.org/shared/maven-archiver/examples/classpath.html#aAdd You can find there how to configure your maven project to run specific class. You have to add maven-jar-plugin configuration with mainClass defined.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
...
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
</configuration>
...
</plugin>
</plugins>
这篇关于Maven生成的jar文件中MANIFEST.MF中缺少Main-class头像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!