美文网首页
Maven-POM文件学习

Maven-POM文件学习

作者: 伊人在水一方_f221 | 来源:发表于2019-07-05 15:33 被阅读0次

一、Maven生命周期

  • clean: 清除构建目录
  • validate: 检查工程配置是否正确,完成构建过程的所有必要信息是否能够获取到。
  • compile: 编译当前源码
  • test: 使用适当的单元测试框架(例如JUnit)运行测试。
  • package: 获取编译后的代码,并按照可发布的格式进行打包,例如 JAR、WAR 或者 EAR 文件
  • verify: 运行检查操作来验证工程包是有效的,并满足质量要求。
  • install: 安装工程包到本地仓库中,该仓库可以作为本地其他工程的依赖。
  • site: 创建新的报告文档、部署站点等
  • deploy: 拷贝最终的工程包到远程仓库中,以共享给其他开发人员和工程。

二、简述

Maven官网文档http://maven.apache.org

What is a POM?

A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that >contains information about the project and configuration details used by Maven to build the >project. It contains default values for most projects. Examples for this is the build directory, >which is target; the source directory, which is src/main/java; the test source directory, which >is src/test/java; and so on. When executing a task or goal, Maven looks for the POM in the >current directory. It reads the POM, gets the needed configuration information, then executes >the goal.
Some of the configuration that can be specified in the POM are the project dependencies, the >plugins or goals that can be executed, the build profiles, and so on. Other information such as >the project version, description, developers, mailing lists and such can also be specified.
POM是Maven依赖的包含当前项目信息以及项目详细配置的XML文件, 即Project Object Module 项目对象模型,是Maven对项目进行管理的依赖。

三、POM基础配置

<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>org.codehaus.mojo</groupId>
  <artifactId>my-project</artifactId>
  <version>1.0-SNAPSHOT</version>
</project>

model 4.0.0是目前Maven2&3唯一支持的解析版本,可以视其为固定节点。

version##

  • SNAPSHOT:快照版本
  • ALPHA:内测版本
  • BETA:公测版本
  • RELEASE:稳定版本
  • GA:正式发布

pom文件节点

pom文件大致可以分为以下几个节点:

<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>...</groupId>
    <artifactId>...</artifactId>
    <version>...</version>
    <packaging>...</packaging>

    <!-- 依赖配置 -->
    <dependencies>...</dependencies>
    <parent>...</parent>
    <dependencyManagement>...</dependencyManagement>
    <modules>...</modules>
    <properties>...</properties>

    <!-- 构建配置 -->
    <build>...</build>
    <reporting>...</reporting>

    <!-- 项目信息 -->
    <name>...</name>
    <description>...</description>
    <url>...</url>
    <inceptionYear>...</inceptionYear>
    <licenses>...</licenses>
    <organization>...</organization>
    <developers>...</developers>
    <contributors>...</contributors>

    <!-- 环境设置 -->
    <issueManagement>...</issueManagement>
    <ciManagement>...</ciManagement>
    <mailingLists>...</mailingLists>
    <scm>...</scm>
    <prerequisites>...</prerequisites>
    <repositories>...</repositories>
    <pluginRepositories>...</pluginRepositories>
    <distributionManagement>...</distributionManagement>
    <profiles>...</profiles>
</project>

1.基础配置信息

<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">
  <!-- pom模型版本,maven2和3只能为4.0.0-->
  <modelVersion>4.0.0</modelVersion>
  <!-- 项目的组ID,用于maven定位-->
  <groupId>com.company.bank</groupId>
  <!-- 项目ID,通常是项目的名称,唯一标识符-->
  <artifactId>parent</artifactId>
  <!-- 项目的版本-->
  <version>0.0.1-SNAPSHOT</version>
  <!-- 项目的打包方式-->
  <packaging>war</packaging>
<project>

pom.xml文件的最外层标签是project标签,该标签定义了如下属性:

  • xmlns属性:表明了该标签下元素的默认命名空间是:http://maven.apache.org/POM/4.0.0,xml文件中,定义命名空间的格式为:xmlns:namespace-prefix="namespaceURI",而定义默认命名空间的格式为:xmlns="namespaceURI";* xmlns:xsi属性:定义了一个namespace-prefix,其代表的命名空间URI为:http://www.w3.org/2001/XMLSchema-instance,定义该命名空间主要是为了更方便的使用其所代表的命名空间中的schemaLocation属性;其中,使用xsi作为namespace-prefix,并不是硬性规定,只是一种通用的选择,当然也可以改成别的命名;* xsi:schemaLocation属性:该属性的使用格式为:xsi:schemaLocation="namespaceURI1 schemaURI1 namespaceURI2 schemaURI2 ...",这里是说使用schemaURI1所对应的schema文件,校验命名空间namespaceURI1下的元素是否符合XML语法规范,后面的则是以此类推。

相关文章

  • Maven-POM文件学习

    一、Maven生命周期 clean: 清除构建目录 validate: 检查工程配置是否正确,完成构建过程的所有必...

  • maven-pom文件结构说明

    maven-pom文件结构说明 1 简介 为了更好的反映代码质量,并且为基础考核提供基础数据,在maven中我们添...

  • 文件学习

  • 群内资源汇总

    1、Unity学习路线:群文件>_学习路线2、Unity学习资源:群文件>学习资料3、游戏开发资源:群文件>资源4...

  • 学习文件

  • 学习文件

  • Python学习-文件系统

    查看所有Python相关学习笔记 文件系统相关知识点 本文学习参考地址 交互学习:Python学习-读写文件 文章...

  • 11.1

    今天继续学习了linux的系统里代码。在linux的系统下编辑文件,后来又学习了如何创建文件和压缩文件还有文件的解...

  • 程序的链接(一):链接的概述

    学习ELF文件,除了要学习其文件格式本身,不可避免要了解其可执行文件的链接过程。这样可以为后续学习Linux/An...

  • 26-磁盘管理(上)

    点击学习!运维发展 点击学习!根目录下文件的作用 点击学习!网卡配置文件内容详解 点击学习!Linux下的故障集合...

网友评论

      本文标题:Maven-POM文件学习

      本文链接:https://www.haomeiwen.com/subject/iodehctx.html