Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 722
Jenny Hilton Avatar asked Aug 27 '17 06:08

Jenny Hilton


People also ask

How do I run a JAR file manifest?

For a JAR file to run, the JAR itself must contain at least one class that has a runnable main method. Furthermore, the class with the main method must be listed as the main-class in the JAR's manifest file. If not, the class must be explicitly stated on the command line when the JAR is run.

What is manifest file in Java JAR?

The manifest is a special file that can contain information about the files packaged in a JAR file. By tailoring this "meta" information that the manifest contains, you enable the JAR file to serve a variety of purposes.


1 Answers

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>
like image 142
Kevin Boone Avatar answered Oct 04 '22 15:10

Kevin Boone