Maven archetype generates a custom project prototype (Template) and mavenarchetype

Source: Internet
Author: User

Maven archetype generates a custom project prototype (Template) and mavenarchetype

Maven archetype can create a project as a project prototype. Then, you only need to create a project using this prototype. Then, the initial project has all the configurations and code in the prototype project. generally speaking, it is a project template.

The plug-ins in eclipse that quickly generate maven projects use the maven prototype function. therefore, if we generate a project prototype that meets our specific needs, we can quickly build the basic project code like using plug-ins.

1. first, we will create a new maven project (the project code must use UTF-8, as to why we will talk about it later), and The artifactId of the project must select some names that are not easy to repeat (the reason is described later ), the recommended format is xxx-xxx. here I created a shiro-auth project:

2. Add the function code and configuration file of the project and ensure that the project encoding format is UTF-8. Add the following configuration in the pom file:

    <properties>        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>      </properties>

3. Run the maven command archetype: create-from-projectto convert the current project to the generated-sources directory under the source project .tar get directory, that is, the code for generating the prototype project.

4. Edit the pom file of the prototype project and add the encoding format and released nexus address:

<properties>        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>      </properties>   <distributionManagement>        <snapshotRepository>            <id>snapshots</id>            <name>Snapshots</name>            <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>        </snapshotRepository>        <repository>            <id>releases</id>            <name>Releases</name>            <url>http://localhost:8081/nexus/content/repositories/releases/</url>        </repository>    </distributionManagement>

5. Run the maven Command deploy to release the prototype project to the nexus repository.

6. In eclipse, click Window --- Preferences --- maven --- Archetypes, click Add Remote Catalog, enter the address in nexus, and take the address of nexus as follows:

Http: // localhost: 8081/nexus/content/groups/public/archetype-catalog.xml, the address of the archetype-catalog.xml file.

 

7. Create a maven project. When selecting Catalog, select the description name we just created. If it is a snapshot project, select include snapshot archetype at the bottom .:

8. Enter basic information such as Artifact and groupId of the new project. Then, a new maven project is generated quickly using the template.

A good memory may ask: why is UTF-8 encoded and complicated names required?

A: 1) I used the template project generated after gbk to generate new projects with garbled code. I tried to specify various codes. If you have any experts, please kindly advise on the trial solution. so I don't want to take the time to go into the UTF-8 encoding directly.

2) The reason why the name must be complex is that the new project generates the pom file according to the template project. The original Artifact name in the template is automatically replaced with the new name, this is only a replacement of all strings. Therefore, if Artifact is the same as some strings in the dependency, the dependent names will be replaced when a new project is generated. therefore, it is better to use some names that are not easy to repeat.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.