Problem с.јаг "No main manifest attribute"

The situation is this: There is a maven project, it has several modules (so you need), there is a class with the main () method, in which certain methods are called, but this is not the point. I'm not familiar with maven, but I need to create a startup jar file for this project. I work in intellij idea, to create a jar I run maven: clean + install, I have created 3 target folders in each module. The main() method is located in the calc-console module.

In the console, I execute java -jar calc-console-1.0-SNAPSHOT.jar and get no main manifest attribute in calc-console-1.0-SNAPSHOT.jar.

Maybe I have a problem with the pom.xml? I did not touch the parent pom, and in the internal pom I specified only the dependencies between the modules (not counting what was already initially generated).

Author: Artem, 2019-04-12

1 answers

The JVM has no idea which class the method is in main, she needs to be prompted. The error text even says how to do this: you need to define the Main-Class attribute in the manifest, the value of which will be the full name of the class. In order for Maven to generate this attribute automatically, you need to add it to pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  ...

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>3.1.1</version>
        <configuration>
          <archive>
            <manifest>
              <mainClass>ЗДЕСЬ ДОЛЖНО БЫТЬ ИМЯ КЛАССА</mainClass>
            </manifest>
          </archive>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
 5
Author: Sergey Gornostaev, 2019-04-12 12:13:36