Home java Problem with .jar “No main manifest attribute”

Problem with .jar “No main manifest attribute”




The situation is this: There is a maven project, there are several modules in it (as needed), there is a class with a 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 runnable jar file for this project. I am working in intellij idea, to create jar i execute maven: clean + install, i have 3 target folders created 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 I get no main manifest attribute in calc-console-1.0-SNAPSHOT.jar.

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

Answer 1, authority 100%

JVM has no idea which class has a main method, 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 contain the full name of the class. For Maven to generate this attribute automatically, you need to add to pom.xml

& lt; 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">
 & lt; build & gt;
  & lt; plugins & gt;
   & lt; plugin & gt;
    & lt; groupId & gt; org.apache.maven.plugins & lt; / groupId & gt;
    & lt; artifactId & gt; maven-jar-plugin & lt; / artifactId & gt;
    & lt; version & gt; 3.1.1 & lt; / version & gt;
    & lt; configuration & gt;
     & lt; archive & gt;
& lt; manifest & gt;
       & lt; mainClass & gt; HERE MUST BE CLASS NAME & lt; / mainClass & gt;
      & lt; / manifest & gt;
     & lt; / archive & gt;
    & lt; / configuration & gt;
   & lt; / plugin & gt;
  & lt; / plugins & gt;
 & lt; / build & gt;
& lt; / project & gt;

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions