Maven的安装与配置及在Eclipe中整合Maven
一、Maven的安装与配置
1、Maven下载和安装
下载maven(maven官网下载)并解压缩
2、Maven的环境配置
2.1 JAVA_HOME配置正确
2.2 MAVEN_HOME配置
2.3 PATH设置
2.4 mvn -v 查看是否安装配置成功
3、Maven相关Setting
3.1 自定义仓库存储位置
<localRepository>D:\Path\apache-maven-3.5.4\repository</localRepository>
3.2 修改mirror
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
3.3 设置jdk版本
<profile>
<id>jdk-1.8</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>
二、Eclipse整合Maven
1、查看本版本Eclipse中是否已经集成Maven插件
若如上操作查看存在Maven选项,则是已经集成了Maven,否则需要安装插件或重新下载安装已经集成了Maven的Eclipes
2、Maven插件的配置
2.1 添加本地安装的Maven
2.2 导入Setting
三、Eclipse创建Maven项目
1、创建maven项目
2、pom.xml文件说明
<!-- project,项目的根标签 -->
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- 工程组标识,通常是公司的域名反写 -->
<groupId>com.zhou.maven</groupId>
<!-- 项目名 -->
<artifactId>TestApp</artifactId>
<!-- 项目版本 -->
<version>0.0.1-SNAPSHOT</version>
<!-- 打包类型,war/jar包 -->
<packaging>war</packaging>
<properties>
<!-- spring版本号 -->
<spring.version>4.3.3.RELEASE</spring.version>
<!-- log4j日志文件管理包版本 -->
<slf4j.version>1.7.7</slf4j.version>
<log4j.version>1.2.17</log4j.version>
<hibernate.version>4.3.8.Final</hibernate.version>
<mysql.version>5.1.42</mysql.version>
</properties>
<!-- jar依赖dependencies -->
<dependencies>
<!-- hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<!-- Servlet的依赖 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!-- jsp的依赖 -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.2.1</version>
<scope>provided</scope>
</dependency>
<!-- spring-core的依赖 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<vrsion>4.2.5.RELEASE</version>
<scope>compile</scope>
</dependency>
<!-- dependencies... -->
</dependencies>
<!-- maven打包插件 -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
3、Maven项目的包结构
3.1 一般web项目
需要手动设置生成webapp及web.xml
在项目上右键——properties