Maven帶有超過40+個Maven模板,讓開發者快速開始一個新的Java項目。這一章,演示怎樣使用Maven的命令“mvn archetype:generate”生成一個新的Java Web項目。
Maven 3.1.0 發布,項目構建工具 http://www.linuxidc.com/Linux/2013-07/87403.htm
Linux 安裝 Maven http://www.linuxidc.com/Linux/2013-05/84489.htm
Maven3.0 配置和簡單使用 http://www.linuxidc.com/Linux/2013-04/82939.htm
Ubuntu下搭建sun-jdk和Maven2 http://www.linuxidc.com/Linux/2012-12/76531.htm
Maven使用入門 http://www.linuxidc.com/Linux/2012-11/74354.htm
下面是使用Maven模板生成項目的步驟。
1、mvn archetype:generate命令
定位到要生成的項目的目錄下,如“D:\workspace\maven-test”。在命令行窗口,執行“mvn archetype:generate -DarchetypeCatalog=internal”命令以生成一個新的項目。Maven將列出已經存在的40+Maven模板項目供我們選擇。在這個例子中,選擇19以創建一個簡單的Java web應用程序項目模板(這裡使用的是Maven 3.03版本,Maven 2可能有所不同):
使用Maven創建項目過程1
D:\workspace\maven-test>mvn archetype:generate -DarchetypeCatalog=internal
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.0:generate (default-cli) @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.0:generate (default-cli) @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.0: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: internal -> appfuse-basic-jsf (AppFuse archetype for creating a web application with Hibernate, Spring and JSF)
2: internal -> appfuse-basic-spring (AppFuse archetype for creating a web application with Hibernate, Spring and Spring MVC)
3: internal -> appfuse-basic-struts (AppFuse archetype for creating a web application with Hibernate, Spring and Struts 2)
4: internal -> appfuse-basic-tapestry (AppFuse archetype for creating a web application with Hibernate, Spring and Tapestry 4)
5: internal -> appfuse-core (AppFuse archetype for creating a jar application with Hibernate and Spring and XFire)
6: internal -> appfuse-modular-jsf (AppFuse archetype for creating a modular application with Hibernate, Spring and JSF)
7: internal -> appfuse-modular-spring (AppFuse archetype for creating a modularapplication with Hibernate, Spring and Spring MVC)
8: internal -> appfuse-modular-struts (AppFuse archetype for creating a modularapplication with Hibernate, Spring and Struts 2)
9: internal -> appfuse-modular-tapestry (AppFuse archetype for creating a modular application with Hibernate, Spring and Tapestry 4)
10: internal -> makumba-archetype (Archetype for a simple Makumba application)11: internal -> maven-archetype-j2ee-simple (A simple J2EE Java application)
12: internal -> maven-archetype-marmalade-mojo (A Maven plugin development project using marmalade)
13: internal -> maven-archetype-mojo (A Maven Java plugin development project)
14: internal -> maven-archetype-portlet (A simple portlet application)
15: internal -> maven-archetype-profiles ()
16: internal -> maven-archetype-quickstart ()
17: internal -> maven-archetype-site-simple (A simple site generation project)
18: internal -> maven-archetype-site (A more complex site project)
19: internal -> maven-archetype-webapp (A simple Java web application)
20: internal -> data-app (A new Databinder application with sources and resources.)
21: internal -> camel-archetype-component (Creates a new Camel component)
22: internal -> camel-archetype-activemq (Creates a new Camel project that configures and interacts with ActiveMQ)
23: internal -> camel-archetype-java (Creates a new Camel project using Java DSL)
24: internal -> camel-archetype-scala (Creates a new Camel project using Scala DSL)
25: internal -> camel-archetype-spring (Creates a new Camel project with added Spring DSL support)
26: internal -> camel-archetype-war (Creates a new Camel project that deploys the Camel Web Console, REST API, and your routes as a WAR)
27: internal -> jini-service-archetype (Archetype for Jini service project creation)
28: internal -> jbosscc-seam-archetype (Maven Archetype to generate a Seam Application- Documentation)
29: internal -> softeu-archetype-seam (JSF+Facelets+Seam Archetype)
30: internal -> softeu-archetype-seam-simple (JSF+Facelets+Seam (no persistence) Archetype)
31: internal -> softeu-archetype-jsf (JSF+Facelets Archetype)
32: internal -> jpa-maven-archetype (JPA application)
33: internal -> spring-osgi-bundle-archetype (Spring-OSGi archetype)
34: internal -> bamboo-plugin-archetype (Atlassian Bamboo plugin archetype)
35: internal -> confluence-plugin-archetype (Atlassian Confluence plugin archetype)
36: internal -> jira-plugin-archetype (Atlassian JIRA plugin archetype)
37: internal -> maven-archetype-har (Hibernate Archive)
38: internal -> maven-archetype-sar (JBoss Service Archive)
39: internal -> wicket-archetype-quickstart (A simple Apache Wicket project)
40: internal -> quickstart (A simple Apache Tapestry 5 Project)
41: internal -> scala-archetype-simple (A simple scala project)
42: internal -> lift-archetype-blank (A blank/empty liftweb project)
43: internal -> lift-archetype-basic (The basic (liftweb) project)
44: internal -> cocoon-22-archetype-block-plain (http://cocoon.apache.org/2.2/maven-plugins/)
45: internal -> cocoon-22-archetype-block (http://cocoon.apache.org/2.2/maven-plugins/)
46: internal -> cocoon-22-archetype-webapp (http://cocoon.apache.org/2.2/maven-plugins/)
47: internal -> myfaces-archetype-helloworld (A simple archetype using MyFaces)
48: internal -> myfaces-archetype-helloworld-facelets (A simple archetype using MyFaces and facelets)
49: internal -> myfaces-archetype-trinidad (A simple archetype using Myfaces and Trinidad)
50: internal -> myfaces-archetype-jsfcomponents (A simple archetype for create custom JSF components using MyFaces)
51: internal -> gmaven-archetype-basic (Groovy basic archetype)
52: internal -> gmaven-archetype-mojo (Groovy mojo archetype)
53: internal -> struts2-archetype-starter (Struts 2 Starter Archetype)
54: internal -> tynamo-archetype (Creates a CRUD web application based on Tapestry 5 and Tynamo, a model-driven Java web framework)
55: internal -> tellurium-junit-archetype (Tellurium JUnit project archetype for the Tellurium Automated Testing Framework)
56: internal -> tellurium-testng-archetype (Tellurium TestNG project archetype for the Tellurium Automated Testing Framework)
57: internal -> scalate-archetype-empty (Generates a Scalate empty web application)
58: internal -> scalate-archetype-guice (Generates a Scalate Jog web application)
Choose a number: 16:
選擇19,Maven會自動下載所需的依賴庫文件,這可能會耗費一些時間。
更多詳情見請繼續閱讀下一頁的精彩內容: http://www.linuxidc.com/Linux/2014-06/103450p2.htm