Write the Maven scaffolding for SpringBoot
Last time we wrote the SpringBoot microservice node, this time we will do it in a much simpler way. Use Maven scaffolding to quickly build microservices.
Maven archetype
What is the archetype
Simply put, The Maven Archetype plugin is a scaffolding for creating projects that you can easily integrate on the command line or IDE.
We can see many archetypes when we use IDEA
It consists of the following modules:
- Maven archetype – pluginArchetype plug-in. This plugin allows developers to use Archetype in Maven.
- Archetype-packaging describes the lifecycle of archetype and the build project software package
- Archetype-models is used to describe classes and references
- Archetype – common core classes
- Archetype-testing is used to test Maven Archetype’s internal components
Archetype plug-ins
maven archetype plugin
- Archetype: Create (not recommended)
Create a Maven project from Archetype.
- archetype:generate
To create a Maven project from archetype, the developer needs to specify the archetype and the plug-in will be automatically retrieved from the remote repository.
-
archetype:create-from-project
Build archetype from existing projects.
-
archetype:crawl
Search and update archetype in the repository.
Create the archetype
- Start by finding a project to use as a template
git clone https://github.com/allennotes/webserver
Copy the code
- Execute in the project root directory, the same directory as the main POM.xml
mvn archetype:create-from-project
Copy the code
- Move the production target directory to the directory we want to open gitbash and do the following
- Example Delete files related to IDEA
rm -rf ./idea
find . -name "*.iml" -type f -print -exec rm -rf {} \;
Copy the code
- Remove unwanted instance code
find . -name "UserMain*" -type f -print -exec rm -rf {} \;
Copy the code
The composition of archetype
-
Prototype files Prototype files
Located in the SRC/main/resources/archetype – the resource directory. The prototype files prototype documents can understand multiple modules in a module or a source file of a single module project. These archetype files are generated when building projects using the corresponding archetype
-
archetype-metadata.xml
Maven/SRC /main/resources/ meta-INF /maven/ This configuration file mainly lists the prototype files and the parameters needed to generate the template project using archetype
-
prototype pom
Located in the SRC/main/resources/archetype – resources directory. This POM file will appear in the archetype template project, if it is a single module project, it is dependency management for the whole project. For a multi-module project, the POM is the general POM file, which defines the submodules of the project and manages the dependencies of the submodules. The submodule POM is defined under the submodules, and the submodule POM file only manages the dependencies of the submodules.
-
archetype pom
Located at the root of the custom Archetype project. This is the ARCHEtype project POM file from which you get local parameters when installing
Install archetype locally
- Run the archetype directory in the same level as pom.xml
mvn install
Copy the code
-
After successful execution, execute the crawl command to generate the archetype-catalog.xml skeleton configuration file in the root directory of the local repository:
MVN archeTYPE :crawl // Update index optionalCopy the code
<?xml version="1.0" encoding="UTF-8"?
<archetype-catalog xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0 http://maven.apache.org/xsd/archetype-catalog-1.0.0.xsd"
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-catalog/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<archetypes
<archetype
<groupIdcom.barm.archetypes</groupId
<artifactIdwebserver-archetype</artifactId
<version1. 0. 0</version
<descriptionDemo project for Spring Boot</description
</archetype
</archetypes
</archetype-catalog
Copy the code
IDEA archeType construction project
Build the project through MVN Archetype: Generate
Create a project from the local archeType template and execute
mvn archetype:generate -DarchetypeCatalog=local
Copy the code
The serial number and then in turn select template groupId, artifactId, version and package information:
Write in the last
It is suggested that you can use it without changing anything, and it is not convenient to change the template project twice to generate scaffolding update. Scaffolding making source https://github.com/allennotes/webserver-archetype
That’s all for this time. Welcome to comment, exchange, pay attention to, like ~