关于项目骨架保存的方法

Maven定义了不少archetype,能够用命令mvn archtype:generate 得到列表,而后更具体提示选择比较适合你的项目骨架。html

可是每一个公司组织都有本身的项目结构习惯,那么怎么把已经公司的项目骨架放到公用的地方让新的项目来套用呢,Maven为咱们提供了很好的工具。java

Maven Archetypes 的功能如同Velocity模板中替换变量,并根据package名等设置扩展java文件的目录结构。apache

1、用 mvn archetype:create-from-project 从已有的项目生成Archetype模板到 target/generated-sources/archetypeapp

处理过程当中,archetype plugin 要找到package name和变量,将变量转为符号,将目录结构和一些文件作拷贝操做。maven

 

2cd target/generated-sources/archetype,而后用mvn install Archetype模板安装到本地maven仓库里。ide

 

三、再你要建立新工程的目录里用mvn archetype:generate -DarchetypeCatalog=local命令 ,按照提示输入项目名,package名等变量,即生成项目工具

不光是apache,还有其余的公司也提供了mavenarchetype项目骨架。很方便。ui


文字太多不形象,画个图。spa

 

附:code

http://maven.apache.org/guides/introduction/introduction-to-archetypes.html

Provided Archetypes

Maven provides several Archetype artifacts:

Archetype ArtifactIds Description
maven-archetype-archetype An archetype which contains a sample archetype.
maven-archetype-j2ee-simple An archetype which contains a simplifed sample J2EE application.
maven-archetype-mojo An archetype which contains a sample a sample Maven plugin.
maven-archetype-plugin An archetype which contains a sample Maven plugin.
maven-archetype-plugin-site An archetype which contains a sample Maven plugin site.
maven-archetype-portlet An archetype which contains a sample JSR-268 Portlet.
maven-archetype-quickstart An archetype which contains a sample Maven project.
maven-archetype-simple An archetype which contains a simple Maven project.
maven-archetype-site An archetype which contains a sample Maven site which demonstrates some of the supported document types like APT, XDoc, and FML and demonstrates how to i18n your site.
maven-archetype-site-simple An archetype which contains a sample Maven site.

 

用法:

 

mvn archetype:create 
  -DgroupId=[your project's group id]
  -DartifactId=[your project's artifact id]
  -DarchetypeArtifactId=maven-archetype-j2ee-simple
相关文章
相关标签/搜索