Maven自定义原型

1. What is Maven Archetype?

Maven原型是一个简单的工件,它包含与项目相关的文件和配置。 使用原型的主要好处是标准化项目开发,并使开发人员可以轻松遵循最佳实践,同时更快地启动其项目。

2. Why we require custom archetype?

很简单 在开发基于其他项目的应用程序时,我们需要一些文件来获取信息并访问其功能。

如此多的配置文件可能包含在您的依赖项目中,例如web.xml,pom.xml and etc..,

pom文件包含所有其他项目所需的依赖项。

在这里,您的项目模板是固定的,并且您知道需要哪些文件以及需要在何处放置这些文件。 最初,您是自己创建的,后来又是重复的工作在开发时新项目一样项目模板。 因此,maven自定义原型可以帮助您创建完全自动化的自定义项目模板。

3. What consists inside of Archetypes?

原型由一个主要的配置文件组成,称为archetype-metadata.xml及其在src / main / resources / META-INF / maven /有一个名为src / main / resources / archetype-resources /它包含您需要进行自定义的所有与项目相关的文件。

即使原型是由项目创建的,所以我们也有一个根pom.xml在原型项目的基本位置。

Maven原型描述符

<requiredProperties>
    <requiredProperty key="version">
        <defaultValue>1.0</defaultValue>
    </requiredProperty>
    <requiredProperty key="client-name"/>
</requiredProperties>

<fileSets>
    <fileSet filtered="true" packaged="true">
        <directory>src/main/java</directory>
        <includes>
            <include>**/*.java</include>
        </includes>
    </fileSet>
     <fileSet filtered="true" packaged="true">
        <directory>src/main/resources</directory>
        <includes>
            <include>**/*.xml</include>
            <include>**/*.properties</include>
        </includes>
    </fileSet>
</fileSets>

<modules>
    <module name="service-module"></module>
    <module name="web-module"></module>
</modules>

requiredProperties标签用于维护任何可配置参数您的项目中需要的。 如果将其设置为默认值,将在创建项目时提示使用其他方式。

文件集将用于维护文件夹。 过滤文件意味着在生成过程中将使用提供的值替换占位符。 所以在我们的项目中客户名称 is required property and i can used this property in any file of filtered 文件集 directory.

模组标签可帮助您拥有多模块项目模板。

for other information, please have a look at the Apache docs

4. Make it Available

Nexus Repo
After a setup of custom archetype you need to make this available for other co-employees. So to do this we have a distributionManagement tag in root pom.xml file where you can maintain your repository to deploy the generated archetype and finally it will be available to others also.

for details how to make a configuration for Nexus, Please check the site Distribution Management in Maven

5. A shortcut way for creating Archetype

Shortcut-image
As i told earlier that first time you created it by your own by using general method to create project using maven. You have your project template ready so it is very simple and only one command you need to use and that is a in-built maven plugin mvn archetype:create-from-project.

转到您的项目模板根文件夹并执行上述命令,maven将自动创建一个自定义原型,它将在基础项目模板的目标位置可用。

这就是帖子的全部内容,我很快会再返回另一篇有用的帖子。 我希望看到您的反馈和建议。

You can follow me on Twitter

from: https://dev.to//iamjaveed59/a-maven-custom-archetype-p3c

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值