Foreword: I believe many friends have encountered some maven packaging failure, here I share my own problems encountered in the process of repackaging, hoping to help you.

This tutorial looks like this: ###1. Dependency delivery failure solution

  • Note the format of the parent class inheritance
  • Is there any mistake in POM? 2. Summarize the error report and provide solutions
  • Failed to execute goal org, apache maven. Plugins: maven – surefire plugin: 2.20.4: test (default – test)
  • ERROR message, is not you write code does not work caused by ERROR ###3. Possible problems with packaging subclass projects through the parent poM
  • Error packaging failed
  • The outgoing subclass package cannot run

All right, start the text. If the problem you are looking for is not listed above, please comment in the comments section below, and we will maintain a summary of Maven’s problems to create the latest and most comprehensive solutions. Thank you for your support!

####1. Dependency transfer failure

Don’t panic when confronted with such problems

Notice a couple of things.

######1.1 Note that the parent class inherits a complete format (especially the relativePath property, which is spoon-free, but not without it!).

<parent> <groupId>com.laojiao</groupId> <artifactId> XXX </artifactId> <version>1.0-SNAPSHOT</version> <relativePath>.. /xxx</relativePath>The poM path of the parent class is written here
	</parent>
Copy the code

######1.2 Notice if there are any errors in the POM

Sometimes if you write a dependent groupId wrong, there will be no error message in the POM. Idea is checked in the Maven Managerment plugin.

You can go here to see if any poM has a problem. If the parent poM has a problem, the introduction of subclasses is invalid. So you’ll see you don’t even have a spring-boot-starter-Web package. – If your parent poM has an error, go to find the parent poM problem.

###2 Packing error reported

#####2.1 Look at the first ERROR message, If Failed to execute goal org. Apache. Maven. Plugins: maven – surefire – plugin: 2.20.4: test (default – test)

If so, it is because you made a mistake in the test class packaging, so I have omitted the test classes here (the test class packaging is not generally included in the JAR).

<! -- Package as an executable jar --> <build> <finalName>springboot-mybatis</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <testFailureIgnore>true</testFailureIgnore>
				</configuration>
			</plugin>
		</plugins>
	</build>
Copy the code

######2.2 Check the first ERROR message to see if the code you wrote does not run properly

If so, run it locally first and then pack it after passing. Or comment out the error and then clean -> package

###3. Possible problems with packaging subclass projects through parent POM

######3.1 Error message you can refer to case 2 if error package fails, you can refer to some solutions mentioned in 2 above #####3.2 Subclass package cannot run (main method cannot be found) If this error occurs, it indicates that the configuration of maven build tool is incorrect. It doesn’t recognize that you need to make executable packages. So add the following configuration

	<build>
		<finalName>xxxx</finalName>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<executions>
					<execution>
						<goals>
							<goal>repackage</goal>
						</goals>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
Copy the code

###### What is a repackage? The most important goal of the Spring Boot Maven plugin is repackage, which can package the packages generated by MVN package into executable packages again in the package life cycle stage of Maven. Maven first generates *.jar files during the package phase. Then run spring-boot:repackage to repackage and find the main-class property configured in the Manifest file

More details can be found in the official documentation: http://docs.spring.io/spring-boot/docs/1.5.4.RELEASE/maven-plugin/ https://docs.spring.io/spring-boot/docs/current/reference/html/build-tool-plugins-maven-plugin.html

Note that the packing tag says jar, because we want jar packages (war packages are similar).

FinalName tells the packaged plug-in what the packaged JAR package is called.

###### Finally, how to run the JAR package. Jar, of course, you have to have the JDK environment first.