1、M2_HOME
E:\apache-maven-3.3.9-bin\apache-maven-3.3.9
2、path
%M2_HOME%/bin
3、本地仓库路径修改
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository -->
<localRepository>E:/mvnjars</localRepository>
4、测试环境
E:\maven_sample\maven_helloworld>mvn -v
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:4
7+08:00)
Maven home: E:\apache-maven-3.3.9-bin\apache-maven-3.3.9
Java version: 1.8.0_102, vendor: Oracle Corporation
Java home: E:\Java\jdk1.8.0_102\jre
Default locale: en_US, platform encoding: GBK
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"
第二、第一个Maven项目编写
1、创建maven文件夹
maven_helloworld
2、在maven_helloworld文件夹中创建
pom.xml
<?xml version="1.0" encoding="utf-8" ?>3、在maven_helloworld\src\main\java\com\zte\mvn目录下创建类HelloMaven.java
<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.zte.mvn.helloworld</groupId> <!--公司开发的某一个项目-->
<artifactId>maven-helloworld</artifactId> <!--这个项目里面具体的某一个模块-->
<version>0.0.1-SNAPSHOT</version>
</project>
package com.zte.mvn;
public class HelloMaven {
public static void main(String[] args){
System.out.printf("hello maven");
}
}
4、编译,第一次编译需要一段时间。因maven需要下载相关的库与依赖插件
E:\maven_sample\maven_helloworld>mvn compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-helloworld 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-hell
oworld ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\maven_sample\maven_helloworld\src\
main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven-helloworl
d ---
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.222 s
[INFO] Finished at: 2016-10-07T09:36:05+08:00
[INFO] Final Memory: 8M/110M
[INFO] ------------------------------------------------------------------------
5、打包
E:\maven_sample\maven_helloworld>mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-helloworld 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-hell
oworld ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\maven_sample\maven_helloworld\src\
main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven-helloworl
d ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ ma
ven-helloworld ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\maven_sample\maven_helloworld\src\
test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ maven-h
elloworld ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ maven-helloworld -
--
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ maven-helloworld ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.685 s
[INFO] Finished at: 2016-10-07T09:37:40+08:00
[INFO] Final Memory: 10M/110M
[INFO] ------------------------------------------------------------------------
执行后将maven_helloworld\target目录下面生成maven-helloworld-0.0.1-SNAPSHOT.jar
6、加入maven仓库
E:\maven_sample\maven_helloworld>mvn install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building maven-helloworld 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ maven-hell
oworld ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\maven_sample\maven_helloworld\src\
main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ maven-helloworl
d ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ ma
ven-helloworld ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\maven_sample\maven_helloworld\src\
test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ maven-h
elloworld ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ maven-helloworld -
--
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ maven-helloworld ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ maven-helloworld
---
[INFO] Installing E:\maven_sample\maven_helloworld\target\maven-helloworld-0.0.1
-SNAPSHOT.jar to E:\mvnjars\com\zte\mvn\helloworld\maven-helloworld\0.0.1-SNAPSH
OT\maven-helloworld-0.0.1-SNAPSHOT.jar
[INFO] Installing E:\maven_sample\maven_helloworld\pom.xml to E:\mvnjars\com\zte
\mvn\helloworld\maven-helloworld\0.0.1-SNAPSHOT\maven-helloworld-0.0.1-SNAPSHOT.
pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.841 s
[INFO] Finished at: 2016-10-07T09:38:25+08:00
[INFO] Final Memory: 11M/106M
[INFO] ------------------------------------------------------------------------