Missing Main-Class attibute in MANIFEST.MF in Mave

2019-08-11 21:30发布

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条回答
Root(大扎)
2楼-- · 2019-08-11 21:54

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>

查看更多
登录 后发表回答