Netbeans 8.2 and maven - no main manifest attribute error

i am using netbeans 8.2 to create a simple java project. i've chosen Maven-Java Application. I've created a simple hello world java class. I've selected the java class as the main class from Properties -> Run and if i run the project from Netbeans, it print the hello world. After that, i do "Clean" and "Build with dependencies" the editor create a target folder with the jar file. When i go to that folder and execute "java -jar XXX.jar", i get the no main manifest attribute error. Do I have to manually update the POM.xml file? Am I missing a step?

728x90

1 Answers Netbeans 8.2 and maven - no main manifest attribute error

I am answering my own question.

Apparently you have to manually update the pom.xml file. I've added the dependency for maven-jar-plugin and added below section to the pom.xml file.

<build>
  <plugins>
    <plugin>
      <!-- Build an executable JAR -->
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <version>3.1.0</version>
      <configuration>
        <archive>
          <manifest>
            <addClasspath>true</addClasspath>
            <classpathPrefix>lib/</classpathPrefix>
            <mainClass>com.mypackage.XXX</mainClass>
          </manifest>
        </archive>
      </configuration>
    </plugin>
  </plugins>
</build>

6 days ago