<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.xxx.XxxApplication</mainClass> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
1.org.springframework.boot:spring-boot-maven-plugin:2.2.1.RELEASE:repackage failed: Unable to find main class
2. Unable to find symbol
If you use SpringBoot packaging plug-in as follows
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
If this packaging plug-in is used, then we must have a class annotated with @SpringBootApplication, otherwise repackage failed: Unable to find main class will be reported when packaging.
If our project packaging is just an ordinary toolkit, then there is no need to add any packaging plug-ins. Maven uses the default method to package it for us without configuration (you can learn about the maven default method configuration online Check, there are many online).
If our project is built in a multi-level build (multi-module) mode, it is just an ordinary module when packaging, but the repackage failed: Unable to find main class error is still reported. This Then we check whether the module's parent project has added the SpringBoot packaging plug-in, because the packaging plug-in will also be inherited. Therefore, it is recommended not to directly add the SpringBoot packaging plug-in to the parent project for convenience. Instead, the Module needs to be packaged as a SpringBoot project and then the SpringBoot packaging plug-in is added.
Regarding maven's default packaging method (as shown below), the package is packaged in jar mode, so there is no need to configure pom.xml, unless we just package it as pom, we can configure< ;packaging>pom, otherwise there is no need to configure it. Of course, the top level of multi-module must be the pom packaging method.
A project has multiple main.class, which causes maven to not know which one to use as the main entrance when packaging. Here we need to set
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.demo.springboot.DemoSbApplication</mainClass> </configuration> </plugin> </plugins> </build>
The reason is usually that when we package the project, we package the project into a jar package and reference other modules.
Other modules are not packaged using jar. For springboot, it is set <packaging>pom</packaging>
. This kind of class must not be found, so we only need Just set the packaging method of that module to <packaging>jar</packaging>
. Note: This may cause Unable to find main class problem.
The above is the detailed content of How to use maven package to specify mainClass in Springboot. For more information, please follow other related articles on the PHP Chinese website!