java Netbeans Maven 项目未将主类添加到清单

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15282098/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 19:05:05  来源:igfitidea点击:

Netbeans Maven Project Not adding Main Class to Manifest

javamavennetbeansdeploymentnetbeans-7

提问by derigible

I am having a similar problem to thisquestion. I have tried all the suggestions listed and am still at a loss. My issue is that I am trying to build a maven project and distribute it to other machines, but the jar files are not being populated with a correct Manifest. Each time I build and run I get the following error: no main manifest attribute, in myjar.jar. Is there some sort of configuration file I need to edit? I just don't know what is going on. I have attempted this fixalso, but to no avail.

我遇到了与问题类似的问题。我已经尝试了列出的所有建议,但仍然不知所措。我的问题是我正在尝试构建一个 Maven 项目并将其分发到其他机器,但是 jar 文件没有填充正确的 Manifest。每次构建和运行时,我都会收到以下错误:no main manifest attribute, in myjar.jar. 我需要编辑某种配置文件吗?我只是不知道发生了什么。我也尝试过此修复程序,但无济于事。

回答by kofemann

You can add it into project's pom file, inside <project>tag:

您可以将其添加到项目的 pom 文件中,<project>标签内:

<build>
    <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-jar-plugin</artifactId>
          <version>2.4</version>
          <configuration>
              <archive>
                  <manifest>
                      <mainClass>your.main.class</mainClass>
                  </manifest>
              </archive>
          </configuration>
      </plugin>
  </plugins>
</build>

回答by fboulay

Another option is to use the maven shade plugin. Unlike the maven jar pluginshowed by tigran, the maven shade pluginincludes your dependencies in the generated jar. A sample usage of the plugin is :

另一种选择是使用maven shade plugin. 与maven jar plugintigran 显示的不同,它maven shade plugin在生成的 jar 中包含您的依赖项。该插件的示例用法是:

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.0</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass>your.main.Class</mainClass>
                </transformer>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>