Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Customize the archetype:create-from-project of Maven Archetype

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

I talked about the method of creating a custom Archetype through the Maven prototype maven-archetype-archetype, but this method does not seem to be convenient to verify the correctness of the file. Here you will use the create-from-project target of the maven-archetype-plugin plug-in to create an archetype from a project

1. Create projectmvn archetype:generate-DgroupId=com.ultrapower.archetypes-DartifactId=ultra-template-archetype-DarchetypeArtifactId=maven-archetype-quickstart-Dversion=1.0-DinteractiveMode=false for creating archetype

It is ignored here about adding related dependencies and so on.

2. Open cmd and execute the following command mvn archetype:create-from-project in the root directory of project

With this command, the generated-sources/archetype directory is generated under the target directory, and this is the generated archetype. (meanwhile, the file archetype-metadata.xml under generated-sources\ archetype\ src\ main\ resources\ META-INF\ maven may need to be adjusted)

First, let's take a look at what the pom.xml under archetype contains.

4.0.0 com.ultrapower.archetypes ultra-template-archetype-archetype 1.0 maven-archetype ultra-template-archetype-archetype org.apache.maven.archetype archetype-packaging 3.0.1 maven-archetype-plugin 3.0.1 Parent pom providing dependency and plugin management for applications built with Maven http:/ / maven.apache.org Pivotal info@pivotal.io Pivotal Software Inc. Http://www.spring.io Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0 https://github.com/spring-projects/spring-boot/spring-boot-starter-parent/ultra-template-archetype

Let's open the archetype-metadata.xml file again and take a look at the contents and make any necessary modifications [may include some files you don't need by default]

Src/main/java * * / * .java * * / * .xml src/main/resources * / * .xml * * / * .html src/main/resources * * / * .yml src/test/java * * / * .java Lib * * / * .jar boot * * / * .bat * * / .sh .settings * * / .prefs .classpath .project

Remove the last two items to meet the needs.

.settings * * / .prefs .classpath .project

Here is a brief description of the meaning of several attributes (for a complete explanation, please refer to the official website archetype-metadata.xml for detailed explanation)

1) filtered: whether the selected file is used as a Velocity template (if it is true, you can use the expression of Velocity, for example, to dynamically set the package name, etc.)

2) packaged: whether the files copied or generated (generated by Velocity) are stored in the directory structure preset by the package attribute

3) encoding: sets the character encoding of the file

3Perminence CD enters the generated-sourced/archetype directory and executes the following command mvn install

By doing this, the custom archetype will be installed into the maven repository, and the custom archetype information will be added to the archetype-catalog.xml file in the repository root directory (the file will not be created automatically)

4. Use custom archetype to create projectmvn archetype:generate-DarchetypeGroupId=com.ultrapower.archetypes-DarchetypeArtifactId=ultra-template-archetype-archetype-DarchetypeVersion=1.0-DgroupId=com.ultrapower.ioss-DartifactId=ultra-template-archetype-test-X

At this point, a new project is generated

Important: the configuration in some java and text files may need to be dynamically modified, so you need to manually adjust the files under archetype, so I won't repeat them here.

After the installation is completed, a file "archetype-catalog.xml" is generated under the root path of the local warehouse, which records the coordinates of the custom skeleton, such as:

Com.ultrapower.archetypes ultra-template-archetype-archetype 1.0 Parent pom providing dependency and plugin management for applications built with Maven

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report