1.搭建Maven环境
1.1检查jdk是否安装:
JAVA_HOME=D:\java\Jdk1.6
%JAVA_HOME%\bin
%JAVA_HOME%\jre\bin
java -version
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode, sharing)
1.2下载安装Maven,下载maven的zip文件,解压后并配置环境变量就可以了
MAVEN_HOME=D:\java\Maven
%MAVEN_HOME%\bin
mvn -v
Apache Maven 3.0.4 (r1232337; 2012-01-17 16:44:56+0800)
Maven home: D:\Java\maven\apache-maven-3.0.4\bin\..
Java version: 1.6.0_24, vendor: Sun Microsystems Inc.
Java home: D:\Java\Jdk 1.6\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows xp", version: "5.1", arch: "x86", family: "windows"
请按任意键继续. . .
注:当Maven由于某些原因(maven升级或原maven安装文件损坏)改变了安装文件的路径,重新配置maven的环境变量并且复制原Maven的配置(比如conf/settings.xml的全局配置)就ok了
1.3Maven优化
1.3.1配置MAVEN_OPTS环境变量(解决内存溢出、乱码问题)
-Xms128m -Xmx512m -Dfile.encoding=UTF-8
mvn -v
会出现这样的语句
Default locale: zh_CN, platform encoding: UTF-8
配置ok
1.3.2在Maven项目中配置 maven 插件
<!--maven plugn version-->
<properties>
<maven-compiler-plugin-version>2.5.1</maven-compiler-plugin-version>
<maven-clean-plugin-version>2.5</maven-clean-plugin-version>
<maven-resources-plugin-version>2.5</maven-resources-plugin-version>
<maven-war-plugin-version>2.3</maven-war-plugin-version>
</properties>
<!--清理插件-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>${maven-clean-plugin-version}</version>
</plugin>
<!-- java文件编译class文件插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin-version}</version>
<configuration>
<encoding>${encoding}</encoding>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
<!--copy resources-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin-version}</version>
<configuration>
<encoding>${encoding}</encoding>
</configuration>
</plugin>
<!--war-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin-version}</version>
<configuration>
<!-- 指定文件,否则"非.java”文件将被忽略 -->
<packagingExcludes>WEB-INF/web.xml</packagingExcludes>
</configuration>
</plugin>