Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No Main Manifest Attribute" in ----.jar Netbeans

Tags:

I recently just started toying around with Maven in java. Time comes to test my project, it works fine in the NetBeans window, running the main class found in App.java (com.MyCompany.App), but when I try to run it from a command line I get an error:

java -jar fileName.jar

"No Main Manifest Attribute" in fileName.jar

I have tried adding a manifest.mf file specifying what main is, I've also been into project properties and added it as the main file...

What's going on?

like image 721
A_Elric Avatar asked Sep 04 '12 15:09

A_Elric


1 Answers

You need the maven-jar-plugin (see Maven's example). This plugin will create the required entries in the manifest file when the project is built.

<project>
  ...
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
              <mainClass>fully.qualified.MainClass</mainClass>
            </manifest>
          </archive>
        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>

You need the version, otherwise, the project won't build. The fully.qualified.MainClass starts at the package hierarchy.

like image 59
yshehab Avatar answered Sep 20 '22 09:09

yshehab