Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netbeans Maven Project Not adding Main Class to Manifest

Tags:

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. 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 fix also, but to no avail.

like image 765
derigible Avatar asked Mar 07 '13 21:03

derigible


People also ask

How do you make a class a main class in NetBeans?

Right-click the user name package and select New -> Java Main Class... Name your class Menu . Run the project. You will be prompted to select the main class.

Does NetBeans not have a main class set?

Make sure all files are saved first. If you try to run a program where the class containing the main method has not been saved, this can happen. Right-click on the project name (in the Projects explorer), then select Properties > Run - and then make sure the main class is selected there.


2 Answers

Another option is to use the maven shade plugin. Unlike the maven jar plugin showed by tigran, the maven shade plugin includes your dependencies in the generated 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>
like image 37
fboulay Avatar answered Sep 19 '22 15:09

fboulay


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

<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>
like image 113
kofemann Avatar answered Sep 17 '22 15:09

kofemann