maven 常用 Archetypes Archetypes简介 什么是原型? 简而言之,Archetype是一个Maven项目模板工具包。原型被定义为原始模式或模型,从中创建所有其他相同类型的东西。 使用原型 要基于Archetype创建新项目,您需要调用mvn archetype:generate ,如下所示: mvn archetype:generate 提供Archetypes Maven提供了几个 Archetypes打包在JAR中,它们包含描述原型内容的原型元数据,以及构成原型项目的一组Velocity模板。
而Maven Archetypes则是Maven提供的一种创建项目骨架的机制,它允许开发者快速启动一个遵循特定结构的新项目,大大节省了初始化配置的时间。 本文将深入浅出地介绍Maven Archetypes的基本概念、常见问题、易错点及避免策略,并附上实用的代码示例。 Maven Archetypes简介 什么是Maven Archetype? 为什么使用Maven Archetypes? 快速开始:无需手动配置项目结构,快速生成标准的项目骨架。 一致性:确保团队中所有项目的结构和配置保持一致,便于维护和协作。 解决方案: mvn archetype:generate 运行上述命令后,Maven会列出一系列可用的Archetypes供你选择。 记住,合理利用Archetypes可以让你的项目从一开始就站在一个良好的起点上,但同时也要注意理解并适当调整生成的配置,以满足项目的具体需求。
Could not resolve artifact org.apache.maven.archetypes:maven-archetype-webapp:pom:RELEASE Failed to resolve version for org.apache.maven.archetypes:maven-archetype-webapp:pom:RELEASE: Could not find metadata org.apache.maven.archetypes:maven-archetype-webapp/maven-metadata.xml in local (C:\Users\liujunguang \.m2\repository) Failed to resolve version for org.apache.maven.archetypes:maven-archetype-webapp:pom :RELEASE: Could not find metadata org.apache.maven.archetypes:maven-archetype-webapp/maven-metadata.xml
默认为 7,快速开发类型; 1: internal -> org.apache.maven.archetypes:maven-archetype-archetype (An archetype which contains a sample archetype.) 2: internal -> org.apache.maven.archetypes:maven-archetype-j2ee-simple (An archetype which contains a simplifed sample J2EE application.) 3: internal -> org.apache.maven.archetypes :maven-archetype-profiles () 7: internal -> org.apache.maven.archetypes:maven-archetype-quickstart (An This archetype can be layered upon an existing Maven project.) 9: internal -> org.apache.maven.archetypes
新建 Maven Project 错误 在使用Eclipse创建Java Maven项目的时候,报错如下: Could not resolve archetype org.apache.maven.archetypes Could not resolve artifact org.apache.maven.archetypes:maven-archetype-quickstart:jar:1.1 Failure to transfer org.apache.maven.archetypes:maven-archetype-quickstart:jar:1.1 from https://repo.maven.apache.org Original error: Could not transfer artifact org.apache.maven.archetypes:maven-archetype-quickstart:jar ---- 设置Archetypes ?
2、如果以上配置没有问题,那就去找到maven安装路径的D:\apache-maven-3.6.3\conf\settings.xml文件,在xml文件找到“mirrors”节点:
Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0) Choose archetype: 1: internal -> org.apache.maven.archetypes:maven-archetype-archetype (An archetype which contains a sample archetype.) 2: internal -> org.apache.maven.archetypes:maven-archetype-j2ee-simple (An archetype :maven-archetype-profiles () 7: internal -> org.apache.maven.archetypes:maven-archetype-quickstart (An This archetype can be layered upon an existing Maven project.) 9: internal -> org.apache.maven.archetypes
第一步 第二步 在IDEA中,我们常用三种骨架 org.apache.maven.archetypes:maven-archetype-quickstart : 打包方式为jar org.apache.maven.archetypes :maven-archetype-webapp : 打包方式为war org.apache.maven.archetypes:maven-archetype-site : 打包方式为pom 第三步 第四步
start 或者maven web project 时: 【1】出现的错误提示: Unable to create project from archetype [org.apache.maven.archetypes :maven-archetype-quickstart:RELEASE] The desired archetype does not exist (org.apache.maven.archetypes
"Archetypes.json"); foreach (ArchetypeTemplate t in tt.Archetypes) { archetypes.Add(new Archetype (t)); } } return archetypes; } Archetype 只是一个来自游戏的任意结构。 它返回了一个非常全面的答案,其中包含以下两个重点: “最后,该方法返回 Archetypes 列表,该列表包含根据 JSON 文件中的模板创建的 Archetype 实例。 ”在此特定方法中,值得注意的是,数据加载和对象实例化仅在 Archetypes 列表为空时执行。 这意味着一旦 Archetypes 被获取一次,后续对该方法的调用将返回相同的列表,而不会进行任何额外的处理。
Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0) Choose archetype: 1: internal -> org.apache.maven.archetypes:maven-archetype-archetype (An archetype which contains a sample archetype.) 2: internal -> org.apache.maven.archetypes:maven-archetype-j2ee-simple (An archetype :maven-archetype-profiles () 7: internal -> org.apache.maven.archetypes:maven-archetype-quickstart (An This archetype can be layered upon an existing Maven project.) 9: internal -> org.apache.maven.archetypes
DgroupId=org.example -DartifactId=test8 -Dversion=1.0-SNAPSHOT -DarchetypeGroupId=org.apache.maven.archetypes [DEBUG] Getting archetypes from catalog: F:\maven\repository\archetype-catalog.xml // 下面这行,意思是容错处理,去中央仓库拉取 如果我们放置的话呢,看看日志是啥样: [INFO] Generating project in Batch mode [DEBUG] Getting archetypes from catalog: F Using the one from [org.apache.maven.archetypes:maven-archetype-quickstart:1.4] found in catalog local image-20230818230727608 mvn命令如何执行该插件 mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes
(An archetype which contains a simplifed sample J2EE application.) 3: internal -> org.apache.maven.archetypes This archetype can be layered upon an existing Maven plugin project.) 5: internal -> org.apache.maven.archetypes :maven-archetype-profiles () 7: internal -> org.apache.maven.archetypes:maven-archetype-quickstart (An archetype which contains a sample Maven project.) 8: internal -> org.apache.maven.archetypes:maven-archetype-site This archetype can be layered upon an existing Maven project.) 9: internal -> org.apache.maven.archetypes
Part I, “Fundamentals” Part II, “Design” Part III, “Layers” Part IV, “Quality Attributes” Part V, “Archetypes Fundamentals of Application Architecture Chapter 2 - .NET Platform Overview Chapter 3 - Application Archetypes Canonical application archetypes to illustrate common application types.
$ mvn -U archetype:generate -Dfilter=io.jenkins.archetypes: ...... Choose archetype: 1: remote -> io.jenkins.archetypes:empty-plugin (Skeleton of a Jenkins plugin with a POM and an empty source tree.) 2: remote -> io.jenkins.archetypes:global-configuration-plugin (Skeleton a Jenkins plugin with a POM and an example piece of global configuration.) 3: remote -> io.jenkins.archetypes number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 3 Choose io.jenkins.archetypes
The other directories (archetypes/, layouts/, and static/) are used when customizing a theme. /archetypes/post.md +++ Description = "" Tags = [] Categories = [] +++ :wq $ find themes/zafta/archetypes -type f | xargs ls -l -rw-r--r-- 1 quoha staff 0 Sep 29 21:53 themes/zafta/archetypes/default.md /post.md +++ Description = "" Tags = [] Categories = [] +++ :wq $ find themes/zafta/archetypes -type f | xargs ls -l -rw-r--r-- 1 quoha staff 0 Sep 29 21:53 themes/zafta/archetypes/default.md -rw-r
按以下步骤来进行你的第一次提交: archetypes 将会是你的内容模板。 添加主题中的 archtypes 至你的博客: Unix 系统: cp themes/kiera/archetypes/* archetypes/ Windows 系统:copy themes\kiera \archetypes\* archetypes\ 选择 Yes 来覆盖原来的 default.md 内容架构类型 创建博客 posts 目录: Unix 系统: mkdir content/posts
其代码如下:from Products.Archetypes import atapifrom Products.CMFCore import utilsdef initialize(context) 以下是如何使用 SchemaExtender 实现代码:from Products.Archetypes.ExtensibleMetadata import SchemaExtenderfrom Products.ATContentTypes.content.event
quick start 或者maven web project 时,如果报如下错误: Unable to create project from archetype [org.apache.maven.archetypes :maven-archetype-quickstart:RELEASE] The desired archetype does not exist (org.apache.maven.archetypes
com.mycompany.example -DartifactId=Example 创建一个java的web工程:mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes