Search code examples
javamavenintellij-ideapom.xml

Run java jar - no main manifest attribute error


I’ve created simple java program (maven with pom ) which when I run some command with CMD it should created a file under given path... I do mvn clean install which finish successfully, Now I want to use this created jar from the command line like follwoing:

java -jar   "/Users/i012/IdeaProjects/myproj/target/test.rts-1.0-SNAPSHOT.jar" path2genfile2create 

Which should run my program (this the first time that I try something like this…)

But the error which Im getting is:

no main manifest attribute, in /Users/i012/IdeaProjects/myproj/target/test.rts-1.0-SNAPSHOT.jar

What could be missing here ? which manifest attribute ?

The error is not coming from the class i’ve created

i've created some META-INF/MANIFEST.MF not helping but maybe Its wrong


Solution

  • If you're using the Maven assembly plug-in, or your IDE tooling is, you need a mainClass element. This is what I use:

    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <mainClass>com.foo.MyMainClass</mainClass>
            </manifest>
          </archive>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
          <id>make-assembly</id>
          <phase>package</phase>
          <goals>
            <goal>single</goal>
          </goals>
          </execution>
        </executions>
      </plugin>