不管你是刚刚接触 maven 的新手,仍是熟练掌握 maven 的大神,相信都能在博主的这篇博客中有所收获。java
仍然记得我在刚刚开始学习 java ,须要引入外部依赖的时候,在网络上处处去寻找 jar 包,那份无奈感直到如今依然刻在个人脑海里。不过,自从了解到 maven 这个工具,我再也没有寻找 jar 包的黑历史了。由于,maven 能够对项目中的 jar 包依赖进行统一管理啊!这个也是 maven 最大的用途了。程序员
若是在项目中咱们不使用 maven 或与之功能类似的工具,在项目中的依赖便须要咱们手动下载,十分的麻烦;可是当咱们使用 maven 构建项目时,maven 为项目提供的 pom 文件能够对项目中全部的依赖进行统一管理,项目中须要的依赖在 pom 文件中直接引入便可,由于 maven 会自动从远程仓库中下载 jar 包到本地仓库。web
在你们了解 maven 的功能以后,咱们也是时候给 maven 下一个定义了。spring
maven 是一个项目管理工具,它具备较高的可重用性,仅仅几行 maven 构建脚本就能够构建简单的项目。maven 中多个项目共享一个本地仓库,每一个项目的 jar 包都依赖于此,并且须要的依赖须要在 pom 文件中进行指定。apache
maven 的命令数其实并很多,咱们这里挑选几个经常使用的来说解一下,毕竟把所有的 maven 命令列举在这里你们也是过眼云烟对不对,不如记住几个经常使用的更有价值。(所有的 maven 命令,博主哪会啊!)tomcat
那么哪几个 maven 命令算常见呢?在 idea 中能够直接使用的这几个 maven 命令,多是各位程序员大神在工做中会常常用到的。网络
咱们前面说过,pom 文件能够对项目中全部的依赖进行统一管理,项目中须要的依赖在 pom 文件中直接引入便可。那么,什么是 pom 文件呢,又或者说,pom 文件长啥样呢?下面咱们来一块儿看看一个 Spring Boot 项目的 pom 文件吧。maven
<?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 https://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.6.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>ok</artifactId> <version>0.0.1-SNAPSHOT</version> <name>ok</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
总结一下,pom 文件包含 maven 项目的依赖关系,打包机制及一些项目的详细信息,它也能够称得上是 maven 中最重要的文件了。ide
三种方式分别为 pom 打包,jar 打包和 war 打包,其中打包方式须要在 pom.xml 中进行指定。svg