Maven的定义:Maven是一个基于项目对象模型(POM)的概念的纯java开发的开源的项目管理工具。主要用来管理java项目,进行依赖管理(jar包依赖管理)和项目构建(项目编译、打包、测试、部署)。此外还能分模块开发,提高开发效率。
一、环境配置
#在配置Maven之前,要保证Java-jdk的环境配置正确,这样才能正确使用
1、此电脑->高级系统设置->环境变量->系统变量->在系统变量中配置MAVEN_HOME和path
分别是maven下的目录
maven下的bin目录
该文件以及对应的bin目录
在控制台输入mvn -v判断是否为安装成功
二、Maven配置
conf->setting.xml
1、本地仓库配置
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<!-- 在此添加本地仓库的路劲 -->
<localRepository>D:\repository</localRepository>
2、jdk配置->这里采用jdk8版本
<profiles>
<!-- 在已有的profiles标签中添加profile标签 -->
<profile>
<id>myjdk</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
</profiles>
3、激活profiles
<activeProfiles>
<!-- 在此添加激活的id -->
<activeProfile>myjdk</activeProfile>
</activeProfiles>
<!-- activeProfiles
| List of profiles that are active for all builds.
|
4、中央仓库在国外,下载依赖速度过慢,所以都会配置一个国内的公共仓库替代中央仓库。
<mirror>
<id>aliyun</id>
<!-- 中心仓库的 mirror(镜像) -->
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<!-- aliyun仓库地址 以后所有要指向中心仓库的请求,都会指向aliyun仓库-->
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
5、私服(学习时不配置,企业要求在配置)
<servers>
<server>
<id>nexus-public</id> <!-- nexus的认证id -->
<username>admin</username> <!--nexus中的用户名密码-->
<password>admin123</password>
</server>
</servers>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus-public</id> <!--nexus认证id 【此处的repository的id要和 <server>的id保持一致】-->
<!--name随便-->
<name>Nexus Release Snapshot Repository</name>
<!--地址是nexus中仓库组对应的地址-->
<url>http://localhost:8081/nexus/content/groups/public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories> <!--插件仓库地址,各节点的含义和上面是一样的-->
<pluginRepository>
<id>nexus-public</id> <!--nexus认证id 【此处的repository的id要和 <server>的id保持一致】-->
<!--地址是nexus中仓库组对应的地址-->
<url>http://localhost:8081/nexus/content/groups/public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>yourjdk</activeProfile>
<!-- 使私服配置生效 -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
三、idea打开
这里Maven就配置好了
先在idea->settings->build,execution->maven
1、先建立一个空的目录,作为我们的存放maven的地方
2、在该目录下建立Maven
3、创建成功
四、webbapp的创建
1、由于maven默认是jar,要创建war,要先更改packaging
<packaging>war</packaging>
2、在project structure->moudules->项目web
3、创建web resource directory 和对应的web.xml
! ! 注意webapp是在main下,创建xml的时候要改变路径