Maven-POM文件学习

2019-07-05  本文已影响0人  伊人在水一方_f221

一、Maven生命周期

二、简述

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##

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标签,该标签定义了如下属性:

上一篇 下一篇

猜你喜欢

热点阅读