maven讲解3:maven项目中的pom.xml是什么?

前言:

一、pom.xml是什么?

POM是项目对象模型(Project Object Model)的简称,它是Maven项目中的文件,使用XML表示,名称叫做pom.xml。作用类似ant的build.xml文件,功能更强大。该文件用于管理:源代码、配置文件、开发者的信息和角色、问题追踪系统、组织信息、项目授权、项目的url、项目的依赖关系等等。事实上,在Maven世界中,project可以什么都没有,甚至没有代码,但是必须包含pom.xml文件。

二、pom.xml文件的结构和内容:

下面是一个POM项目中的pom.xml文件中包含的元素。注意,其中的modelVersion是4.0.0,这是当前仅有的可以被Maven2&3同时支持的POM版本,它是必须的。

<?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>
    <packaging> ... </packaging>
    
    <!-- 基本设置  -->
    <parent>
        <groupId> ... </groupId>
        <artifactId> ... </artifactId>
        <version> ... </version>
    </parent>
    <groupId>...</groupId>
    <artifactId>...</artifactId>
    <version>...</version>
    
    <!--  属性配置(版本号也在这儿配置) -->
    <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>
        。。。
        <shop-center-api-version> ... </shop-center-api-version>
        <order-center-api-version> ... </order-center-api-version>
        <finpay-center-api-version> ... </finpay-center-api-version>
    </properties>
    
    <!--  模块(本项目的所有模块)-->
    <modules>
   		 <module> ... </module>
         <module> ...  </module>
         。。。
    </modules>
    
     <!--  依赖  -->
     <dependencyManagement> 
	    <dependencies>
	   		 <dependency>
	             <groupId> ... </groupId>
	             <artifactId> ... </artifactId>
	             <version> ... </version>
	         </dependency>
	         。。。
	         
	    </dependencies>
	    
    </dependencyManagement>
    
    <!--  构建过程的设置  -->
    <build>
        <plugins>
       		<plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                    <executable>false</executable>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            。。。
        </plugins>
    </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>

三、pom.xml文件中的内容讲解:

  1. packaging标签讲解: https://blog.csdn.net/weixin_40763897/article/details/105405106

  2. dependencyManagement和dependencies标签的区别:https://blog.csdn.net/jiangyu1013/article/details/52424726

  3. pluginManagement和plugins标签的区别:https://blog.csdn.net/zhangxitab/article/details/91039954

  4. dependencies标签下的dependency标签中的依赖:从这儿获取
    https://mvnrepository.com/

  5. plugins标签下的plugin标签中的插件: https://www.infoq.cn/news/2011/04/xxb-maven-7-plugin/
    https://www.infoq.cn/news/2011/05/xxb-maven-8-plugin/

四、学习链接:

链接1:https://blog.csdn.net/ckc_666/article/details/82965150
链接2:https://blog.csdn.net/jiangyu1013/article/details/52424726

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值