使用Maven模板Archetype创建项目

模板分为公开模板与私有模板,区别是否可以通过公网使用;

1、本地存在的公共模板查看

mvn archetype:generate 或 mvn org.apache.maven.plugins:maven-archetype-plugin:2.2:generate  (指定插件版本,因maven总是使用最新的版本,有时是快照版,存在bug)

1: internal -> org.appfuse.archetypes:appfuse-basic-jsf (AppFuse archetype for creating a web application with Hibernate, Spring and JSF)
2: internal -> org.appfuse.archetypes:appfuse-basic-spring (AppFuse archetype for creating a web application with Hibernate, Spring and Spring MVC)
3: internal -> org.appfuse.archetypes:appfuse-basic-struts (AppFuse archetype for creating a web application with Hibernate, Spring and Struts 2)
4: internal -> org.appfuse.archetypes:appfuse-basic-tapestry (AppFuse archetype for creating a web application with Hibernate, Spring and Tapestry 4)
5: internal -> org.appfuse.archetypes:appfuse-core (AppFuse archetype for creating a jar application with Hibernate and Spring and XFire)
6: internal -> org.appfuse.archetypes:appfuse-modular-jsf (AppFuse archetype for creating a modular application with Hibernate, Spring and JSF)
7: internal -> org.appfuse.archetypes:appfuse-modular-spring (AppFuse archetype for creating a modular application with Hibernate, Spring and Spring MVC)
8: internal -> org.appfuse.archetypes:appfuse-modular-struts (AppFuse archetype for creating a modular application with Hibernate, Spring and Struts 2)
9: internal -> org.appfuse.archetypes:appfuse-modular-tapestry (AppFuse archetype for creating a modular application with Hibernate, Spring and Tapestry 4)
10: internal -> org.makumba:makumba-archetype (Archetype for a simple Makumba application)
11: internal -> org.apache.maven.archetypes:maven-archetype-j2ee-simple (A simple J2EE Java application)
12: internal -> org.apache.maven.archetypes:maven-archetype-marmalade-mojo (A Maven plugin development project using marmalade)
13: internal -> org.apache.maven.archetypes:maven-archetype-mojo (A Maven Java plugin development project)
14: internal -> org.apache.maven.archetypes:maven-archetype-portlet (A simple portlet application)
15: internal -> org.apache.maven.archetypes:maven-archetype-profiles ()
16: internal -> org.apache.maven.archetypes:maven-archetype-quickstart ()
17: internal -> org.apache.maven.archetypes:maven-archetype-site-simple (A simple site generation project)
...... 51: internal -> org.codehaus.gmaven.archetypes:gmaven-archetype-basic (Groovy basic archetype) 52: internal -> org.codehaus.gmaven.archetypes:gmaven-archetype-mojo (Groovy mojo archetype) 53: internal -> org.apache.struts:struts2-archetype-starter (Struts 2 Starter Archetype) 54: internal -> org.tynamo:tynamo-archetype (Creates a CRUD web application based on Tapestry 5 and Tynamo, a model-driven Java web framework) 55: internal -> tellurium:tellurium-junit-archetype (Tellurium JUnit project archetype for the Tellurium Automated Testing Framework) 56: internal -> tellurium:tellurium-testng-archetype (Tellurium TestNG project archetype for the Tellurium Automated Testing Framework) 57: internal -> org.fusesource.scalate.tooling:scalate-archetype-empty (Generates a Scalate empty web application) 58: internal -> org.fusesource.scalate.tooling:scalate-archetype-guice (Generates a Scalate Jog web application) 59: local -> com.mysoft:TcpDump-archetype (TcpDump-archetype) Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 16:

 通过输入编号使用对应模板即可

2、本地不存在的公共模板使用

mvn archetype:generate \
 -DgroupId=com.alibaba.webx \
 -DartifactId=tutorial1 \
 -Dversion=1.0-SNAPSHOT \
 -Dpackage=com.alibaba.webx.tutorial1 \
 -DarchetypeArtifactId=archetype-webx-quickstart \
 -DarchetypeGroupId=com.alibaba.citrus.sample \
 -DarchetypeVersion=1.8 \
 -DinteractiveMode=false

 

 由于Windows下不支持命令换行,请改用非换行版
命令执行完后,你会看见一个新目录:tutorial1。它就是我们刚刚创建的新项目。项目的各项参数如下所示:

  项目组(groupId):com.alibaba.webx。
  项目名称(artifactId):tutorial1
  项目版本(version):1.0-SNAPSHOT。
  项目中Java类的包名(package):com.alibaba.webx.tutorial1。
[注意]   
你完全可以根据你的需要来调整上述命令中的参数,改用其它的groupId、artifactId、version以及package。

但其他的不可以修改,因为其他的就是模板的真实信息

3、查看本地私有模板

mvn archetype:generate -DarchetypeCatalog=local

T:\cb07\Downloads>mvn archetype:generate -DarchetypeCatalog=local
[WARNING]
[WARNING] Some problems were encountered while building the effective settings
[WARNING] Unrecognised tag: 'snapshots' (position: START_TAG seen ...</pluginGroup> -->\n\t\t\t\n    <snapshots>... @50:16)  @ D:\java\apache-maven-3.2.3\conf\settings.xml, line 50, column 16
[WARNING]
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.4:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.4:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.4:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
1: local -> com.mysoft:TcpDump-archetype (TcpDump-archetype)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): :

 

 选择1后,根据提示输入生成项目信息即可

4、制作私有模板

1、进入需要制作成模板的项目的根目录下
  mvn archetype:create-from-project 生成模板信息
2、将生成target/generated-sources/archetype的信息,可进行调整
   mvn clean install –DskipTests 安装模板到maven

3、本地使用私有模板
   mvn archetype:generate -DarchetypeCatalog=local
注意:
  mvn eclipse:eclipse 将代码转化为eclipse项目
  mvn eclipse:clean 清除eclipse相关信息

 

5、maven常用命令,红色跳过是固定的

mvn clean                清除生成文件
mvn compile              编译代码
mvn test-compile         编译测试代码
mvn test                 运行测试mvn package -DskipTests     项目打包并不执行测试代码,生成target目录,编译、测试代码,生成测试报告,生成jar/war文件
mvn install            将项目打包并将生成的jar包安装到maven本地库中
mvn install -Dmaven.test.skip=true  安装跳过测试 mvn jar:jar            只打jar包,其余的插件不执行 mvn
-version/-v 显示版本信息 mvn archetype:generate 创建mvn项目 mvn jetty:run 运行项目于jetty上 mvn tomcat:run 运行项目于tomcat上
mvn clean install        删除再编译
mvn install -X         想要查看完整的依赖踪迹,包含那些因为冲突或者其它原因而被拒绝引入的构件,打开 Maven 的调试标记运行

 

posted @ 2016-12-08 17:18  W&L  阅读(1040)  评论(0编辑  收藏  举报