一、maven:自动化构建和项目管理工具
1、项目管理工具:使用pom.xml 管理jar包。团队合作中,项目的jar包版本管理和团队之间lib包拷来拷去的麻烦共睹,使用maven来从中央仓库,私服,本地仓库获取jar包,只需在项目中 maven \ maven update , 尤其在大型微服务化项目中管理多个层级的父项目,子项目jar包版本统一管理更是让人欲罢不能。嘿嘿,pom在手,天下我有。
2、自动化构建工具:项目测试管理,代码编译,代码打包发布,比ant 方便些。
二、maven安装
1、资源下载:http://maven.apache.org/download.cgi
Binary zip archive | apache-maven-3.5.0-bin.zip |
下载后解压到本地】
2、配置环境变量:
先确保安装了jdk; 新建环境变量:M2_HOME 值为D:\dev\apache-maven-3.5.0 maven目录; 加入Path:在Path中追加;%M2_HOME%\bin
在控制台 mvn -v 可以看到
三、配置setting.xml
在D:\dev\apache-maven-3.5.0\conf\settings.xml中配置maven的仓库信息,
1、本地仓库: <localRepository>D:\dev\mavenRepo</localRepository>
2、远程仓库:我自己机器配置maven 中央仓库:http://repo1.maven.org/maven2
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url> http://repo1.maven.org/maven2</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url> http://repo1.maven.org/maven2</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
四、eclipse配置maven
在window/preferences/Maven/User Settings 中配置
五、创建maven项目
1、项目maven坐标:
2、可以定制自己的项目骨架,常用的java project 和 web project;
3、pom.xml:maven基于pom管理项目
<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.lls</groupId>
<artifactId>mavenTest</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>mavenTest 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>mavenTest</finalName>
</build>
</project>
4、项目管理文件
六、maven构建命令
1、maven update :刷新项目jar包,可以package Explore视图中看到项目下的 Maven Dependencies 看到项目的jar包
2、在 Run As / Run Configurations / Macen Build / new Configuration 中配置 构建,
也可以在控制台 cd 到项目文件目录后 mvn clean install -DMaven.test.skip=true; 跳过测试
//本文只是作为初步使用资料,maven多个部分,maven pom.xml文件参数和管理项目方式,maven 插件,maven构建命令,maven私服仓库都值得详细深入学习
//觉得每次安装环境都不太记得,留点记录,第一次在csdn上写博客,图片原来是先上传再插入的,和自己开发的一致,却有点麻烦,更真心感谢写原创的各位猿媛同辈了