maven快速入门

maven是基于JAVA平台的自动化构建工具

和maven有同样用途的工具还有以下:

make—-ant—-maven—–gradle

主要用途就是便于管理第三方jar包,方便jar包的下载,jar包之间版本的关系

maven的仓库主要分为本地仓库,中央仓库和多个远程镜像仓库,加载jar包时先从本地仓库再到中央仓库

 

 

 

 

 

maven的官网下载地址:http://maven.apache.org/download.cgi

下载二进制包,解压后,配置环境变量,在cmd窗口中运行mvn -v 能查到安装的版本,则表示安装成功。

 

JavaProject的pom.xml文件说明
1、pom意思就是project object model。
2、pom.xml包含了项目构建的信息,包括项目的信息、项目的依赖等。
3、pom.xml文件是可以继承的,大型项目中,子模块的pom.xml一般都会继承于父模块的pom.xml

pom.xml文件的内容如下:

 

<?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">
    <modelVersion>4.0.0</modelVersion>
    
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    
    <groupId>com.example</groupId>
    <artifactId>mybaitis</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>mybaitis</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.0.0</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.14</version>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.5</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <!--添加mybatis generator maven插件-->
            <plugin>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-maven-plugin</artifactId>
            <version>1.3.5</version>
            <configuration>
                <!--generatorConfig.xml位置-->
                <configurationFile>src/main/resources/mybatis-generator/generatorConfig.xml</configurationFile>
                <verbose>true</verbose>
                <overwrite>true</overwrite>
            </configuration>
            <executions>
                <execution>
                    <id>Generate MyBatis Artifacts</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <phase>generate-sources</phase>
                </execution>
            </executions>
            <!--此处必须添加mysql驱动包-->
            <dependencies>
        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
                <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    <version>8.0.14</version>
                </dependency>

            </dependencies>
            </plugin>
        </plugins>
    </build>

</project>

  

 

其中由groupId、artifactId和version唯一的确定了一个项目坐标