Maven 学习1:
1.下载Maven软件包apache-maven-3.1.1-bin.zip,解压到D盘。D:\apache-maven-3.1.1
2.配置环境变量,配置系统变量Path 为(配置内容D:\apache-maven-3.1.1\bin)D:\apache-maven-3.1.1\bin
3.打开Cmd窗口,输入 mvn -v 回车.
窗口打印出:
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-
2+0800)
Maven home: D:\apache-maven-3.1.1\bin\..
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: C:\Program Files (x86)\Java\jdk1.7.0_25\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
表示配置成功,maven版本为 3.11
4.在D盘创建一个TestBuild文件夹,在TestBuild文件夹内创建pox.xml文件,将项目工程拷贝到TestBuild文件夹中。
5.打开Cmd窗口,输入 d: 回车,定位到D盘,在输入 cd TestBuild 回车,定位到TestBuild文件夹中。
6.输入 mvn package (D:\TestBuild>mvn package) (打包发布命令),回车
<dependencies> <!-- 项目引入插件所需要的额外依赖 Jar等-->
<contributors> <!-- 项目的其他贡献者列表 -->
cmd窗口会输出很多打包的相关信息,最后输出 BUILD SUCCESS 表示打包成功。
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ gts-manage ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ gts-manage ---
[INFO] Packaging webapp
[INFO] Assembling webapp [gts-manage] in [D:\TestBuild\target\gts]
[INFO] Processing war project
[INFO] Copying webapp resources [D:\TestBuild\gts\WebContent]
[INFO] Webapp assembled in [3113 msecs]
[INFO] Building war: D:\TestBuild\target\gts.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO] -----------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] -----------------------------------------------------------------------
[INFO] Total time: 6.724s
[INFO] Finished at: Fri Apr 24 16:36:12 CST 2015
[INFO] Final Memory: 6M/17M
[INFO] -----------------------------------------------------------------------
D:\TestBuild>
7.在D:\TestBuild文件夹中生成target文件夹,target文件夹中生成gts.war 和 gts项目文件夹。
常用命令:
mvn package 打包发布命令
mvn compile 编译项目命令
mvn clean 清理项目命令
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.test.gts</groupId> <artifactId>gts-manage</artifactId> <version>1.0</version> <packaging>war</packaging> <name>Gts Manage System</name> <build> <finalName>gts</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <!--指定web.xml文件的位置--> <webXml>gts\WebContent\WEB-INF\web.xml</webXml> <!--指定jsp等文件所在位置--> <warSourceDirectory>gts\WebContent</warSourceDirectory> </configuration> </plugin> </plugins> </build> </project>