zoukankan      html  css  js  c++  java
  • maven pom.xml文件详解

    一 POM.xml简介

    看一个简单的小例子

    <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/maven-v4_0_0.xsd">
        

        <modelVersion>4.0.0</modelVersion>
        <groupId>com.xy.company</groupId>
        <artifactId>MavenResource</artifactId>
        <packaging>jar</packaging>
        <version>1.0-SNAPSHOT</version>
        <name>MavenResource</name>
        <url>http://maven.apache.org</url>

        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>3.8.1</version>
                <scope>test</scope>
            </dependency>
        </dependencies>

    </project>

    pom.xml文件基本节点介绍:


    <project>文件的根节点。

    <modelversion>pom.xml使用的对象模型版本。


    <groupId>创建项目的组织或团体的唯一Id。


    <artifactId>项目的唯一Id,可视为项目名。


    <packaging>打包物的扩展名,一般有JAR,WAR,EAR等。


    <version>产品的版本号。


    <name>项目的显示名,常用于Maven生成的文档。


    <url>组织的站点,常用于Maven生成的文档,可以放你公司的主页地址。


    <description>项目的描述,常用于Maven生成的文档。


    <repositories>资源地址,所有的依赖包将从次地址下载,其中如果snapshot为资源快照,相对不稳定,而release为稳定版本。


    <pluginRepositories> 插件地址,因为maven的所有功能都是使用插件来实现功能的,因此需要从特定的地址下载插件包。
     

    <build>功能集标签,在此标签下面可以定义一系列的插件以实现功能,常用插件有以下两种:
    • maven-surefire-plugin单元测试的插件,在此插件下面可以设置一些列的参数
    • maven-compiler-plugin代码编译插件,在用此插件的时候一定要设置source的版本,默认的是JDK1.3


    <dependencies>项目需要的所有依赖的包。

    其中repositories和pluginRepositories就是放私服的地址,即我们前几讲的nexus的public仓库组地址。

    <project >

        <modelVersion>4.0.0</modelVersion>
        <groupId>com.xy.company</groupId>
        <artifactId>MavenResource</artifactId>
        <packaging>jar</packaging>
        <version>1.0-SNAPSHOT</version>
        <name>MavenResource</name>
        <url>http://maven.apache.org</url>

    <repositories>
        <repository>
         <id>xy-central</id>
         <name>xycentral</name>
         <url>http://localhost:8080/nexus-2.2-01/content/groups/public/</url>
         <releases>
          <enabled>true</enabled>
         </releases>
         <snapshots>
          <enabled>false</enabled>
         </snapshots>
        </repository>
      </repositories>


      <pluginRepositories>
      <pluginRepository>
       <id>xy-central</id>
       <name>xycentral</name>
       <url>http://localhost:8080/nexus-2.2-01/content/groups/public/</url>
       <layout>default</layout>
       <snapshots>
        <enabled>false</enabled>
       </snapshots>
       <releases>
        <updatePolicy>never</updatePolicy>
       </releases>
      </pluginRepository>
     </pluginRepositories>

        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>3.8.1</version>
                <scope>test</scope>
            </dependency>
        </dependencies>

    </project>

    二 客户端下载包流程

    比如客户端需要一个junit的jar包

    第一步:到本地仓库找该jar包,找到结束。没找到下一步。

    第二步:到pom配置的私服仓库去找,即pom.xml配置的repositories标签。如找到下载到本地仓库并引用。没找到下一步。

    第三步:到maven的中央仓库去找,如找到同时下载到本地仓库和私服的central仓库并引用。

  • 相关阅读:
    正向代理和反向代理
    Unicode
    utf-8
    ISO 8895-1
    ProtocalBuffers学习记录
    C#基础知识
    MSBuild学习记录
    Linux学习笔记
    Jenkins学习记录
    CruiseControl.Net学习记录
  • 原文地址:https://www.cnblogs.com/jswang/p/6927301.html
Copyright © 2011-2022 走看看