Missing Main-Class attibute in MANIFEST.MF in Maven generated jar file

守給你的承諾、 提交于 2020-01-05 21:21:03

问题


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.

Why does Maven not add this attribute?


回答1:


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>



来源:https://stackoverflow.com/questions/21968104/missing-main-class-attibute-in-manifest-mf-in-maven-generated-jar-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!