The content of this article is about how to use maven to package and publish springboot. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
This article shares how to use maven to facilitate us to create springboot release packages; I use the idea development tool here, and first create a project structure of multiple modules, as shown in the figure:
To package projects of multiple modules, the packaged plug-ins are generally configured in the parent pom. The pom of other modules does not require special configuration. When the configuration is completed, click The package of the maven tool in idea can perform a series of packaging operations;
Here first use the maven-jar-plugin plug-in and add the following configuration in the parent pom:
org.apache.maven.plugins maven-jar-plugin 2.4 true lib/ com.platform.WebApplication
We need to pay attention to the following nodes in the above configuration:
mainClass: We need to specify the main entrance, of course This is not necessary. If there are multiple main entries in the same project, it is only needed when packaging. Only one main entry is actually ignored;
classpathPrefix: Specify to add to the classpath The prefix folder name where the dependent package is located
addClasspath: the dependent package is added to the classpath, the default is true
includes: needs to be included in the jar The files in are generally not configured (note: if the configuration path is inappropriate, the class may be excluded)
excludes: If you are making an external configuration file for the jar package, you need to do this here Use excludes to exclude these configuration files and package them in the jar together.
Use the maven-jar-plugin plug-in to package the project. At this time, you can package it through the maven package command and you can see the jar. There is a lib folder (default), which contains third-party dependency packages introduced in the project. Through java -jar xxx.jar, you can see that the jar is successfully started:
In standard projects, there are generally dev, test, uat, pro and other environments. Different configurations are required for these environments. In springboot, different configurations can be distinguished by application-dev|test|...yml. Just add spring.profiles.active=dev|test... to the default application.yml;
This method has inconveniences, such as local debugging or publishing and online need to be modified back and forth. The active value (of course, when starting through jar, you can also set the command line active parameter) is not very convenient; below, configure profiles in the pom, and then select the configuration used for startup by clicking on the idea interface; first, in the main layer Create the configuration file directory with the following structure:
In order to distinguish the tests, server.port is set for different environment configuration files to specify different ports (dev: 3082, pro: 3182)
Then, configure the following profiles information in the parent pom:
dev true dev test test uat uat pro pro
Node description:
activeByDefault :Set as the default running configuration
activeProfile: The selected startup configuration, its value corresponds to the dev|test|pro folder under the profiles created above
Then, add the resources node configuration to the build in the pom:
src/main/profiles/${activeProfile}
At this moment our configuration is complete. Under normal circumstances, the maven module on the idea can see such a picture. Surface:
At this time, we only need to check these buttons. Whether it is debugging or final packaging, follow this to obtain the required configuration files.
The above is the detailed content of How to use maven to package and release springboot. For more information, please follow other related articles on the PHP Chinese website!