简体   繁体   English

Netbeans Maven项目不将Main Class添加到Manifest

[英]Netbeans Maven Project Not adding Main Class to Manifest

I am having a similar problem to this question. 我对这个问题有类似的问题。 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. 我的问题是我正在尝试构建一个maven项目并将其分发给其他机器,但jar文件没有填充正确的Manifest。 Each time I build and run I get the following error: no main manifest attribute, in myjar.jar . 每次构建和运行时,我都会收到以下错误: 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 fix also, but to no avail. 我也试过这个修复 ,但无济于事。

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>

Another option is to use the maven shade plugin . 另一种选择是使用maven shade plugin Unlike the maven jar plugin showed by tigran, the maven shade plugin includes your dependencies in the generated jar. 与tigran显示的maven jar plugin不同, maven shade plugin包含生成的jar中的依赖项。 A sample usage of the plugin is : 该插件的示例用法是:

  <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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM