Creating an archetype is a pretty straight forward process. An archetype is a very simple plugin, that contains the project prototype you wish to create. An archetype is made up of:
- an archetype descriptor (archetype.xml in directory: src/main/resources/META-INF/). It lists all the files that will be contained in the archetype and categorizes them so they can be processed correctly by the archetype generation mechanism.
- the prototype files that are copied by the archetype (directory: src/main/resources/archetype-resources/)
- the prototpye pom (pom.xml in: src/main/resources/archetype-resources)
- a pom for the archetype (pom.xml in the archetype's root directory).
To create an archetype follow these steps:
1. Create a new project and pom.xml for the archetype plugin
An example pom.xml for an archetype plugin looks as follows:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>my.groupId</groupId>
<artifactId>my-archetype-id</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
</project>
All you need to specify is a groupId, artifactId and version. These three parameters will be needed later for invoking the archetype via archetype:create from the commandline.
2. Create the archetype descriptor
The archetype descriptor is a file called archetype.xml which must be located in src/main/resources/META-INF/ An example for an archetype descriptor can be found in the quickstart archetype:
<archetype>
<id>quickstart</id>
<sources>
<source>src/main/java/App.java</source>
</sources>
<testSources>
<source>src/test/java/AppTest.java</source>
</testSources>
</archetype>
The <id> tag should be the same as the artifactId in the archetype pom.xml.
An optional <allowPartial>true</allowPartial> tag makes it possible to run the archetype:create even on existing projects.
The <sources>, <resources>, <testResources> and <siteResources> tags represent the different sections of the project:
- <sources> = src/main/java
- <resources> = src/main/resources
- <testSources> = src/test/java
- <testResources> = src/test/resources
- <siteResources> = src/site
<sources> and <testSources> can contain <source> elements that specify a source file.
<testResources> and <siteResources> can contain <resource> elements that specify a resource file.
Place other resources such as the ones in the src/main/webapp directory inside the <resources> tag.
At this point one can only specify individual files to be created but not empty directories.
Thus the quickstart archetype shown above defines the following directory structure:
archetype
|-- pom.xml
`-- src
`-- main
`-- resources
|-- META-INF
| `-- archetype.xml
`-- archetype-resources
|-- pom.xml
`-- src
|-- main
| `-- java
| `-- App.java
`-- test
`-- java
`-- AppTest.java
3. Create the prototype files and the prototype pom.xml
The next component of the archetype to be created is the prototype pom.xml. Any pom.xml will do, just don't forget to the set artifactId and groupId as variables ( ${artifactId} / ${groupId} ). Both variables will be initialized from the commandline when calling archetype:create.
An example for a prototype pom.xml is:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<packaging>jar</packaging>
<version>${version}</version>
<name>A custom project</name>
<url>http://www.myorganization.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
4. Install and run the archetype
Now you are ready to install the archetype:
mvn install
Now that you have created an archetype you can try it on your local system by using the following command. In this command, you need to specify the full information about the archetype you want to use (its groupId, its artifactId, its version) and the information about the new project you want to create (artifactId and groupId). Don't forget to include the version of your archetype (if you don't include the version, you archetype creation may fail with a message that version:RELEASE was not found)
mvn archetype:create \
-DarchetypeGroupId=<archetype-groupId> \
-DarchetypeArtifactId=<archetype-artifactId> \
-DarchetypeVersion=<archetype-version> \
-DgroupId=<my.groupid> \
-DartifactId=<my-artifactId>
Once you are happy with the state of your archetype you can deploy (or submit it to ibiblio) it as any other artifact and the archetype will then be available to any user of Maven.
Alternative way to start creating your Archetype
Instead of manually creating the directory structure needed for an archetype, simply use
mvn archetype:create
-DgroupId=[your project's group id]
-DartifactId=[your project's artifact id]
-DarchetypeArtifactId=maven-archetype-archetype
Afterwhich, you can now customize the contents of the archetype-resources directory, and archetype.xml, then, proceed to Step#4 (Install and run the archetype plugin).
分享到:
相关推荐
《The Definitive Guide to Plone 2nd Edition》是一本深入探讨Plone内容管理系统(CMS)的专业指南,尤其针对其3.x版本进行了全面的更新。这本书为读者提供了丰富的知识,帮助他们理解和掌握Plone的强大功能,从而...
当在Eclipse中创建一个Maven项目时,为了快速启动开发,我们可以选择使用Maven Archetypes。Archetypes是预定义的项目模板,它们可以自动生成一个具有基本结构的项目,从而简化初始化过程。 **什么是Maven ...
1. 查询Archetypes:开发人员可以通过Maven的`archetype:generate`命令,结合Archetypes-Catalog.xml文件,列出所有可选的Archetypes,以便选择合适的模板。 2. 创建项目:选择合适的Archetype后,输入相应的ID,...
【标题】"appverse-web-archetypes-源码.rar" 提供的是 AppVerse Web Archetypes 的源代码,这是一个用于快速构建Web应用的框架或者模板集合。AppVerse 是一个旨在简化企业级应用程序开发的项目,而Web Archetypes ...
《PyPI官网下载:探索Python库archetypes.configure》 在Python的世界里,PyPI(Python Package Index)是不可或缺的一部分,它是Python开发者获取和分享软件包的主要平台。本篇文章将聚焦于一个名为`archetypes....
《PyPI官网下载 | archetypes.clippingimage-2.0.tar.gz》 在Python的世界里,PyPI(Python Package Index)是最重要的软件仓库之一,它为开发者提供了丰富的Python库资源。今天我们要关注的是一个名为"archetypes....
《PyPI官网下载 | archetypes.multilingual-1.0b2.tar.gz——探索Python多语言支持库》 PyPI(Python Package Index),是Python开发者获取和分发软件包的主要平台。在PyPI官网上,我们可以找到各种各样的Python库...
**PyPI 官网下载 | Products.Archetypes-1.7.2.zip** 在Python的世界里,PyPI(Python Package Index)是官方的第三方软件包仓库,它为开发者提供了发布和分享他们创建的Python模块、库和其他工具的平台。用户可以...
标题 "flexmojos-archetypes-library-6.0.1.zip" 暗示这是一个关于FlexMojos的开源项目库,版本为6.0.1。FlexMojos是Maven插件,专为Adobe Flex和Apache Flex项目提供构建支持。它允许开发者使用Maven生命周期来编译...
Spring-Maven-Archetypes是Spring框架提供的一套Maven模板,用于快速构建Spring项目,显著减少了开发初期的配置工作,从而提高工作效率。这个工具利用了Maven Archetype插件的功能,允许开发者根据预定义的模板生成...
资源分类:Python库 所属语言:Python 资源全名:archetypes.querywidget-1.1.1.zip 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
Furthermore, you'll take advantage of Maven's archetypes to bootstrap new projects easily. Finally, you will learn how to integrate Nexus repository manager with Maven release phases. After reading ...
先决条件JDK 11 Maven 3在本地安装原型要将所有原型安装在本地存储库中,请执行以下命令: git clone https://github.com/openjfx/javafx-maven-archetypes.gitcd javafx-maven-archetypesmvn clean install...
gwt-maven-原型 该项目包含模块化GWT项目的Maven原型。 如何使用 生成一个项目 mvn archetype:generate \ -DarchetypeGroupId=... git clone https://github.com/tbroyer/gwt-maven-archetypes.g
Camunda Maven原型 这些是项目模板,可用于快速启动... 如果要在我们的问题跟踪器中创建问题,则可以添加名为archetypes的component 。 完整文件 《 提供了Maven原型的完整文档。 执照 该存储库中的源文件在下可用。
在IT行业中,特别是在Java开发领域,"archetypes"是一个重要的概念,它与软件开发的模板化过程密切相关。Archetypes是Maven项目对象模型(Project Object Model, POM)的一个组成部分,用于创建新项目的骨架或者模板...
在IT行业中,Maven Archetypes 是一个非常重要的概念,它为开发者提供了一种创建Maven项目模板的方法。标题“archetypes:一组有用的原型”表明这是一个关于Maven Archetypes的资源集合,可能包含了多种预定义的项目...