There is a project with the following build options:

<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <outputDirectory>${basedir}</outputDirectory> <finalName>supermega</finalName> <appendAssemblyId>false</appendAssemblyId> <archive> <manifest> <mainClass>main.Main</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </build> 

When I build a project with IntelliJ Idea , clicking on Plugins->assembly->assembly:single , then everything is ok. But when I go to the project folder, enter the mvn assembly:single command, everything is fine, but when I try to start it, an error occurs:

 Error: Could not find or load main class main.Main 

I can not understand in any way where the Main class disappears when building via the console.

  • I edited the answer, now I see the code in it, check it out. - Nick Volynkin

1 answer 1

add the pom plugin below, rebuild and check

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.0.2</version> <configuration> <archive> <manifest> <mainClass>main.Main</mainClass> <!-- тут правильный путь укажи --> </manifest> </archive> </configuration> </plugin> 
  • Isn't that what it is? `<manifest> <mainClass> main.Main </ mainClass> </ manifest>` - faoxis
  • I mean, is a class added to the manifest itself? - keekkenen
  • How can this be verified? - faoxis
  • open the jar file with the archiver and see what is written in META-INF \ MANIFEST.MF - keekkenen
  • Hey. It looks like you could not format the xml so that it is normally displayed in the question. I corrected the formatting, it was enough four spaces before each line of code (this is Markdown markup). - Nick Volynkin