Maven带有超过40+个Maven模板,让开发者快速开始一个新的Java项目。这一章,演示怎样使用Maven的命令“mvn archetype:generate”生成一个新的Java Web项目。
下面是使用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会自动下载所需的依赖库文件,这可能会耗费一些时间。
2、项目详细信息
接下来,会让填写项目的详细信息:
填写项目详细信息
Define value for property 'groupId': : com.xuejava
Define value for property 'artifactId': : com.xuejavaweb
Define value for property 'version': 1.0-SNAPSHOT: : 1.0
Define value for property 'package': com.xuejava: :
完整的过程如下:
项目生成过程2
……
Choose a number: 16: 19
Downloading: http://repo1.maven.org/maven2/org/apache/maven/archetypes/maven-arc
hetype-webapp/1.0/maven-archetype-webapp-1.0.jar
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/archetypes/maven-arch
etype-webapp/1.0/maven-archetype-webapp-1.0.jar (4 KB at 1.7 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/archetypes/maven-arc
hetype-webapp/1.0/maven-archetype-webapp-1.0.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/archetypes/maven-arch
etype-webapp/1.0/maven-archetype-webapp-1.0.pom (533 B at 0.1 KB/sec)
Define value for property 'groupId': : com.xuejava
Define value for property 'artifactId': : com.xuejavaweb
Define value for property 'version': 1.0-SNAPSHOT: : 1.0
Define value for property 'package': com.xuejava: :
Confirm properties configuration:
groupId: com.xuejava
artifactId: com.xuejavaweb
version: 1.0
package: com.xuejava
Y: : y
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Old (1.x) Archetype:
maven-archetype-webapp:RELEASE
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: com.xuejava
[INFO] Parameter: packageName, Value: com.xuejava
[INFO] Parameter: package, Value: com.xuejava
[INFO] Parameter: artifactId, Value: com.xuejavaweb
[INFO] Parameter: basedir, Value: D:\workspace\maven-test
[INFO] Parameter: version, Value: 1.0
[INFO] ********************* End of debug info from resources from generated POM ***********************
[INFO] project created from Old (1.x) Archetype in dir: D:\workspace\maven-test\com.xuejavaweb
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:13.922s
[INFO] Finished at: Sun May 22 13:51:03 CST 2011
[INFO] Final Memory: 6M/16M
[INFO] ------------------------------------------------------------------------
D:\workspace\maven-test>
创建结束,会生成如下的文件和目录结构:
3、pom.xml
在Maven中,pom.xml文件是项目配置的核心,它包含构建项目所需的主要信息。在上面的示例中,自动生成了pom.xml文件,其中的标签“packaging”为“war”—注意这里不是“jar”。当使用Maven构建项目时,该项目将自动打成war包用来部署。
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xuejava</groupId>
<artifactId>com.xuejavaweb</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>com.xuejavaweb Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>com.xuejavaweb</finalName>
</build>
</project>
在Maven,完成所有这一切,只需要一个命令,就可以创建标准目录结构,马上开始开发工作。
分享到:
相关推荐
使用Maven模板创建项目 使用Maven构建项目 使用Maven清理项目 使用Maven运行单元测试 将项目安装到Maven本地资源库 生成基于Maven的项目文档站点 使用“mvn site-deploy”部署站点(WebDAV例子) 部署基于Maven的war...
详细介绍maven制作模板流程,及发布过程,以及用模板生成maven项目。
Maven 打包生成Windows和Liunx启动文件模板
NULL 博文链接:https://skywhsq1987.iteye.com/blog/1513736
自己实现的自定义maven插件:可以根据配置的接口类和参数类,生成对应的word版本的API文档。还可以自定义自己的模板文件。
一个简单的Maven项目 3.1. 简介 3.1.1. 下载本章的例子 3.2. 创建一个简单的项目 3.3. 构建一个简单的项目 3.4. 简单的项目对象模型 (Project Object Model) 3.5. 核心概念 3.5.1. Maven插件和目标 ...
dockerfile-maven-插件一个基于模板生成 Dockerfile 的 Maven 插件。 = 用法 = == pom.xml == 将以下插件声明添加到您的 pom.xml: <build> [..] <plugin> <groupId>org.acmsl</groupId> <artifactId>dockerfile-...
这是一份采用Java编写的基于Poi1.9.1的...源码采用Maven进行依赖构建,下载后,可以直接在代码编辑器如eclipse或者idea中打开,除了依赖一个poi-tl这个核心包之外,无其它第三方的bao依赖,保持最小的干扰,方便运行。
FreeMarker模板引擎不错,使用非常简单,其实可以做很多事情,比如代码自动生成,按格式生成work文件等,这里简单的实现了按照实体生成建表语句、action、biz、dao和对应的xml文件等
是java普通项目,直接导入MyEclipse即可运行即可使用(已包含jar包,没有数据库),代码注释很清楚,网上很多都是maven项目,且bug很多,现已进行修复。main方法执行即可生成。
:party_popper: 一个用于测试和试验各种Maven插件和配置的游乐场。 外挂程式 :electric_plug: Maven插件 项目 描述 网站 Maven资源插件 处理项目资源到输出目录的复制 Maven执行器插件 要求通过配置(自定义)...
Maven模板创建一个最小的,基于最佳实践的Adobe Experience Manager(AEM)项目作为您网站的起点。 文献资料 :原型架构及其不同模块的概述。 以下教程基于该原型: :了解如何启动一个全新的网站。 WKND SPA...
本项目Github地址:https://github.com/yu Chenggroup/rapid- generator 项目最初来自于https://code.google.com/p/rapid-generator/ 增加一些定制和扩展,修改为基于MAVEN...其他一些模板使用上的修改,参考模板目录
这个插件使您的带有夸张注解的项目能够在maven构建阶段生成夸张的规格和可定制的模板化静态文档。与swagger-core不同,swagger-maven插件并不主动地将规范服务于应用程序的其余部分;它生成规范作为构建工件,用于...
与其他解决方案不同,它作为插件紧密集成在Maven构建过程中,不需要特定的站点布局或复杂的设置:只需放入几个Markdown页面和一个Pug / Less模板,然后由生成器来处理细节… 用法 配置插件 将插件添加到您的构建...
matlab算法,毕设、课设程序,全部源码均已进行严格测试,可以直接运行! matlab算法,毕设、课设程序,全部源码均已进行严格测试,可以直接运行! matlab算法,毕设、课设程序,全部源码均已进行严格测试,可以直接...
基于maven的Java web项目框架模板,使用spring + spring_mvc + mybatis + spring-data-redis等框架各种配置文件都已写好的并实现了一个简单的登陆注册功能可用于在IDEA上快速构建网络项目或入门学习 更多spring_mvc...
该项目是一个Maven扩展工具,旨在帮助开发者快速搭建基于YMP框架的各种Java工程结构。系统提供了丰富的功能,包括项目模板生成、依赖管理、插件集成等。通过该项目,开发者可以学习并实践Java技术的应用,为后续的...