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.
            Asked
            
        
        
            Active
            
        
            Viewed 2.1k times
        
    20
            
            
        2 Answers
49
            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>
- 
                    You know how many of these hacks I had to use to make a Netbeans Java Maven project run like a Netbeans Java Ant project? Why don't they make this more seamless? – trilogy Jul 20 '21 at 19:05
- 
                    Don't try to make it look like ant. Use https://en.m.wikipedia.org/wiki/Convention_over_configuration to keep your software as maven standard project to avoid custom configurations. – kofemann Jul 20 '21 at 19:37
- 
                    How else do you assume I create a distributable jar file with dependencies ? I need a lib folder with the dependency jars, and I need an executable jar that includes the classpath to that folder, and I need that jar to know what the main class is. None of these features come out of the box for a maven project. Has nothing to do with conventions. – trilogy Jul 20 '21 at 19:46
30
            
            
        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>
 
    
    
        fboulay
        
- 401
- 3
- 5
 
     
     
    