使用maven创建项目

Archetype是Maven的一个插件,用户可以方便的使用它快速的创建Maven项目。在Maven3中,为了创建一个基于Archetype的新项目,你需要在命令行中执行mvn archetype:generate,像这样:
mvn archetype:generate

在回车后,项目将开始创建。从Archetype创建一个项目将执行下面3个步骤:
 1)archetype的选择;
 2)archetype的配置;
 3)用户输入项目信息,并根据项目信息创建工程。
我们可以在命令行中看到下面的信息:

$ mvn archetype:generate
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [archetype:create] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] Preparing archetype:generate
[INFO] No goals needed for project - skipping
[INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: velocimacro.messages.on => 'false'.
[INFO] Setting property: resource.loader => 'classpath'.
[INFO] Setting property: resource.manager.logwhenfound => 'false'.
[INFO] [archetype:generate]
Choose archetype:
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.apache.maven.archetypes:maven-archetype-j2ee-simple (A simple J2EE Java application)
11: internal -> org.apache.maven.archetypes:maven-archetype-marmalade-mojo (A Maven plugin development project using marmalade)
12: internal -> org.apache.maven.archetypes:maven-archetype-mojo (A Maven Java plugin development project)
13: internal -> org.apache.maven.archetypes:maven-archetype-portlet (A simple portlet application)
14: internal -> org.apache.maven.archetypes:maven-archetype-profiles ()
15: internal -> org.apache.maven.archetypes:maven-archetype-quickstart ()
16: internal -> org.apache.maven.archetypes:maven-archetype-site-simple (A simple site generation project)
17: internal -> org.apache.maven.archetypes:maven-archetype-site (A more complex site project)
18: internal -> org.apache.maven.archetypes:maven-archetype-webapp (A simple Java web application)
19: internal -> org.apache.struts:struts2-archetype-starter (A starter Struts 2 application with Sitemesh, DWR, and Spring)
20: internal -> org.apache.struts:struts2-archetype-blank (A minimal Struts 2 application)
21: internal -> org.apache.struts:struts2-archetype-portlet (A minimal Struts 2 application that can be deployed as a portlet)
22: internal -> org.apache.struts:struts2-archetype-dbportlet (A starter Struts 2 portlet that demonstrates a simple CRUD interface with db backing)
23: internal -> org.apache.struts:struts2-archetype-plugin (A Struts 2 plugin)
......
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 15:

在这里,你需要做出一个选择,选择一种archetype,archetype就是一个模板,Maven将根据模板创建和模板匹配的项目,完整的archetype的信息你可以在http://repo1.maven.org/maven2/archetype-catalog.xml查看,目前有7000多种archetype,我们只需要关心和我们项目相关的,或者了解一些通用的(前面20多种)就可以了,在这里,我选择2(创建一个使用Hibernate、Spring和Spring MVC的web应用),默认是选择15(一个简单的带有单元测试的java工程)。选择后继续:

Choose br.gov.frameworkdemoiselle.archetypes:demoiselle-jsf-jpa version:
1: 2.3.0-RC2
2: 2.3.0-RC3
3: 2.3.0
4: 2.3.1
5: 2.3.2
6: 2.3.3
7: 2.3.4
8: 2.4.0-BETA1
9: 2.4.0-BETA2
10: 2.4.0-BETA3
11: 2.4.0-RC1
Choose a number: 11:

在这里,选择默认,继续输出:

Define value for property 'groupId': :

这里,你需要输入groupid,groupid定义了项目属于哪个组,这个组往往和项目所在的组织或公司存在关联,例如:org.apache.maven.plugins。输入groupid后回车:

Define value for property 'artifactId': :

继续输入artifactId,artifactId定义了当前Maven项目在组中唯一的ID,artifactId也是项目输出的结果的基础名称,例如:如果输出为一个jar包,artifactId为myapp,则输出为myapp-1.0.jar( <artifactId>-<version>.<extension>)。输入后继续:

Define value for property 'version':  1.0-SNAPSHOT: :

这个输出项目的版本,根据需要输入,一般为1.0,可以加snapshot后缀说明项目还处于开发中,是不稳定版本,随着项目的发展,version会不断更新。输入后继续:

Define value for property 'package':  org.crazyrobot: :

定义创建项目默认的包名。输入后继续:

Confirm properties configuration:
groupId: mygroupId
artifactId: artifactId
version: 1.0
package: mygroupId
 Y: :

在这里确认你输入的信息,如果没问题则直接回车,将输出一些版本信息后结束,项目创建成功,你可以打开你创建的项目,在根目录下可以看到pom.xml文件,打开可以看到创建项目是输入的信息。


 

 

 

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值