1.maven的核心是pom.xml,通常有以下元素:
groupId:表示项目所属的组
artifactId:表示唯一的标识,两者相加称为项目坐标
packaging:项目类型,常用的为jar和war
version:项目版本号
dependencies:包含多个dependency,用来声明项目的依赖,是pom最核心的位置
dependency:用来声明项目的依赖
scope:代表此类库与项目的关系,默认是complie,就是编译和打包都需要此类库;test指只在单元测试使用;provided是编译阶段使用,打包阶段不使用,可能项目的目标环境已经提供了;runtime指在编译和打包都不需要,但在运行时需要,比如数据库驱动。
build:包含多个插件plugin,用来辅助项目构建
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.secoo</groupId>
<artifactId>secoo-studio</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<name>secoo-studio</name>
<description>寺库拍照系统</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
<java.version>1.8</java.version>
</properties>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<conf.dir>${project.basedir}/src/main/resources/profile/dev</conf.dir>
<ver_type>-DEV-SNAPSHOT</ver_type>
</properties>
<build>
<resources>
<resource>
<directory>${conf.dir}</directory>
</resource>
</resources>
</build>
</profile>
<profile>
<id>test</id>
<properties>
<conf.dir>${project.basedir}/src/main/resources/profile/test</conf.dir>
<ver_type>-SNAPSHOT</ver_type>
</properties>
<build>
<resources>
<resource>
<directory>${conf.dir}</directory>
</resource>
</resources>
</build>
</profile>
<profile>
<id>pro</id>
<properties>
<conf.dir>${project.basedir}/src/main/resources/profile/pro</conf.dir>
<ver_type>.RELEASE</ver_type>
</properties>
<build>
<resources>
<resource>
<directory>${conf.dir}</directory>
</resource>
</resources>
</build>
</profile>
</profiles>
<dependencies>
<!--start springboot web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 添加对thymeleaf的支持 -->
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- spring boot and redis-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- redis依赖commons-pool 这个依赖一定要添加 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.5.0</version>
</dependency>
<!-- start 数据库-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.10</version>
</dependency>
<dependency>
<groupId>io.shardingjdbc</groupId>
<artifactId>sharding-jdbc-core</artifactId>
<version>2.0.1</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.shardingjdbc</groupId>
<artifactId>sharding-jdbc-core-spring-namespace</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<!-- end 数据库-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.22</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.29</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.22</version>
</dependency>
<dependency>
<groupId>com.github.cage</groupId>
<artifactId>cage</artifactId>
<version>1.0</version>
</dependency>
<!-- httpclient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.1.3</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient-cache</artifactId>
<version>4.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.1.3</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.1.4</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!-- httpclient end -->
<!--<dependency>-->
<!--<groupId>com.secoo</groupId>-->
<!--<artifactId>prices-rpc</artifactId>-->
<!--<version>0.2.5${ver_type}</version>-->
<!--</dependency>-->
</dependencies>
<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.properties</exclude>
<exclude>**/*.xml</exclude>
</excludes>
</resource>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>application.properties</include>
<include>mybatis-config.xml</include>
</includes>
</resource>
<!--SpringBoot启动脚本打到target目录-->
<resource>
<directory>${project.basedir}/boot</directory>
<targetPath>..</targetPath>
</resource>
</resources>
<finalName>secoo-studio</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>ttf</nonFilteredFileExtension>
<nonFilteredFileExtension>woff</nonFilteredFileExtension>
<nonFilteredFileExtension>woff2</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
<!-- 跳过单元测试 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<skip>true</skip>
<!-- 忽略单元测试失败 -->
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<!-- mybatis generator 自动生成代码插件 -->
<!--<plugin>-->
<!--<groupId>org.mybatis.generator</groupId>-->
<!--<artifactId>mybatis-generator-maven-plugin</artifactId>-->
<!--<version>1.3.5</version>-->
<!--<dependencies>-->
<!--<dependency>-->
<!--<groupId>mysql</groupId>-->
<!--<artifactId>mysql-connector-java</artifactId>-->
<!--<!–<scope>runtime</scope>–>-->
<!--<version>8.0.13</version>-->
<!--</dependency>-->
<!--</dependencies>-->
<!--<executions>-->
<!--<execution>-->
<!--<id>Generate MyBatis Artifacts</id>-->
<!--<phase>package</phase>-->
<!--<goals>-->
<!--<goal>generate</goal>-->
<!--</goals>-->
<!--</execution>-->
<!--</executions>-->
<!--<configuration>-->
<!--<!–允许移动生成的文件 –>-->
<!--<verbose>true</verbose>-->
<!--<!– 是否覆盖 –>-->
<!--<overwrite>true</overwrite>-->
<!--<!– 自动生成的配置 –>-->
<!--<configurationFile>-->
<!--src/main/resources/generator/mybatis-generator.xml</configurationFile>-->
<!--</configuration>-->
<!--</plugin>-->
</plugins>
</build>
</project>
2.settings.xml添加仓库镜像
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
3.eclipse引用maven
4.maven常用命令
mvn complie:编译maven工程
mvn package:编译并打包工程
mvn install:打包并安装到本地仓库
mvn deploy:同install,但打包并安装到远程仓库
mvn clean:删除target目录