Maven的pom.xml文件

pom作为项目对象模型。通过xml表示maven项目,使用pom.xml来实现。

主要描述了项目:包括的配置文件;开发者需要遵循的规则,缺陷管理系统,组织和licenses,项目的url,项目的依赖性,以及其他所有的项目相关因素。

一个基本项目的pom.xml文件,通常至少有三个部分:

第一部分:项目坐标,信息描述等

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.company.project</groupId>  //com.公司名.项目名
    <artifactId>module</artifactId>  //功能模块名
    <packaging>war</packaging>  //项目打包的后缀,war是web项目发布用的,默认为jar
    <version>0.0.1-SNAPSHOT</version> //artifact模块的版本
    <name>test Maven Webapp</name> //相当于项目描述,可删除
    <url>http://maven.apache.org</url>  ////相当于项目描述,可删除
    
    //父项目的坐标
    //group id + artifact id +version :项目在仓库中的坐标
    <parent>
        <groupId>com.xxx.xxx</groupId>
        <artifactId>xxxx</artifactId>
        <version>1.0.0</version>
    </parent>
    
    //项目开发者属性,如即时消息如何处理等
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <poi.version>3.16</poi.version>
        <docker.image.prefix>pms</docker.image.prefix>
        <spring-cloud.version>Dalston.SR4</spring-cloud.version>
    </properties>
    

第二部分:引入jar包


    //dependency:引入资源jar包到本地仓库,要引入更多资源就在<dependencies>中继续增加<dependency>
    //group id+artifact id+version:资源jar包在仓库中的坐标
    //scope:作用范围,test指该jar包仅在maven测试时使用,发布时会忽略这个包。需要发布的jar包可以忽略这一配置
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

需要引入什么包可以来这个地址搜索http://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-eureka/1.4.5.RELEASE

这个网页有如下代码,可以直接复制粘贴。

image

第三部分,构建项目

//build:项目构建时的配置
//finalName:在浏览器中的访问路径,如果将它改成helloworld,再执行maven--update,这时运行项目的访问路径是 http://localhost:8080/helloworld/   而不是项目名的  http://localhost:8080/test
//plugins:插件,之前篇章已经说过,第一个插件是用来设置java版本为1.7,第二个插件是我刚加的,用来设置编码为utf-8
//group id+artifact id+version:插件在仓库中的坐标
//configuration:设置插件的参数值

<build>
    <finalName>helloworld</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.0.1</version>
            <configuration>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
    </plugins>
</build>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,253评论 19 139
  • maven的pom.xml文件配置详解 setting.xml主要用于配置maven的运行环境等一系列通用的属性,...
    ProZoom阅读 1,748评论 0 6
  • 前阵子工作中用Python对xml格式的配置文件的内容进行修改,使用的模块是Python内置的xml.etree....
    Ivanlfli阅读 4,762评论 2 8
  • 原文作者:Hafiz.Zhang来源网址:http://www.cnblogs.com/hafiz 史上最全的ma...
    Exclusive丶阅读 145评论 0 0
  • 当你的记忆, 划过我的天际, 当你的双眸, 游过我的心底。 满满的爱意, 传遍我的身体。 我激动的记起, 这是你的...
    橘子洲的鱼阅读 330评论 2 3