Maven环境搭建

第一、环境变量配置与配置文件修改

1、M2_HOME

E:\apache-maven-3.3.9-bin\apache-maven-3.3.9

2、path
%M2_HOME%/bin

3、本地仓库路径修改
[html]  view plain  copy
  1. <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"  
  2.           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.           xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">  
  4.   <!-- localRepository  
  5.    | The path to the local repository maven will use to store artifacts.  
  6.    |  
  7.    | Default: ${user.home}/.m2/repository -->  
  8.   <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
[html]  view plain  copy
  1. <?xml version="1.0" encoding="utf-8" ?>  
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"    
  3.   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
  4.   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0    
  5.                       http://maven.apache.org/maven-v4_0_0.xsd">  
  6. <modelVersion>4.0.0</modelVersion>   
  7. <groupId>com.zte.mvn.helloworld</groupId>  <!--公司开发的某一个项目-->  
  8. <artifactId>maven-helloworld</artifactId>  <!--这个项目里面具体的某一个模块-->  
  9. <version>0.0.1-SNAPSHOT</version>  
  10. </project>  
3、在maven_helloworld\src\main\java\com\zte\mvn目录下创建类HelloMaven.java
[java]  view plain  copy
  1. package com.zte.mvn;  
  2. public class HelloMaven {  
  3.    public static void main(String[] args){  
  4.        System.out.printf("hello maven");  
  5.    }  
  6. }  


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] ------------------------------------------------------------------------
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值