maven项目的pom.xml文件常用标签使用介绍

导读:本篇文章讲解 maven项目的pom.xml文件常用标签使用介绍,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

文章来源:

http://blog.csdn.net/javaloveiphone/article/details/52080886

一丶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/xsd/maven-4.0.0.xsd">

  <!-- 指定了当前POM的版本 -->
  <modelVersion>4.0.0</modelVersion>

  <!-- 项目坐标信息 -->
  <!-- 项目主标识,用于定义当前项目属于的实际项目,格式与项目创建的包是一样的,公司域名反写-->
  <groupId>com.jsun.demo</groupId>
  <!-- 项目名或模块名或项目名+模块名组成 -->
  <artifactId>demo-maven01</artifactId>
  <!-- 当前项目版本号,一般由三个数字组成,第一个0表示大版本号,第二个0表示分支版本号,第三个1表示小版本号 -->
  <!-- SNAPSHOT代表当前版本类型为快照版本,还有alpha内部版本、beta公测版本、release发布版本、ga正式版本等 -->
  <version>0.0.1-SNAPSHOT</version>
  <!-- maven打包方式,默认为jar,还有:pom,maven-plugin,war,rar,zip -->
  <packaging>jar</packaging>

  <!-- 用在子模块中,实现对父模块的继承 -->
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.5.RELEASE</version>
  </parent>

  <!-- 聚合多个maven项目,同时对所有聚合项目进行编译 -->
  <modules>
    <module></module>
  </modules>

  <!-- 项目描述名,url,详细描述,产生项目文档使用 -->
  <name>Maven01</name>
  <url>http://maven.apache.org</url>
  <description>测试maven项目</description>

  <!-- 开发人员列表,项目发布使用 -->
  <developers>
    <!-- 某个项目开发者的信息 -->
    <developer>
        <!-- 项目开发者的唯一标识符 -->
        <id>001</id>
        <!-- 项目开发者的全名 -->
        <name>jsun</name>
        <!-- 项目开发者的email -->
        <email> jsun@163.com </email>
        <!-- 项目开发者的主页的URL -->
        <url />

        <!-- 项目开发者在项目中扮演的角色,角色元素描述了各种角色 -->
        <roles>
            <role>developer</role>
        </roles>

        <!-- 项目开发者所属组织 -->
        <organization>com-jsun</organization>
        <!-- 项目开发者所属组织的URL -->
        <organizationUrl> http://demo.jsun.com/jsun</organizationUrl>   
    </developer>
  </developers>


  <!-- 许可证信息, -->
  <licenses>
    <license>
        <name></name>
        <!-- 官方的license正文页面的URL -->
        <url></url>
        <!-- 项目分发的主要方式:repo,可以从Maven库下载,manual,用户必须手动下载和安装依赖 -->
        <distribution></distribution>
        <!-- 关于license的补充信息 -->
        <comments></comments>
    </license>
  </licenses>

  <!-- 项目所属组织信息 -->
  <organization>
      <name></name>
      <url></url>
  </organization>


  <!-- 属性列表,相当于定义的公共常量,引用方式比如:${project.build.sourceEncoding} -->
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <junit.version>3.8.1</junit.version>
  </properties>

  <!-- 依赖列表 -->
  <dependencies>
    <!-- 具体依赖项,下面主要包含依赖的坐标、类型、范围等信息 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>1.2.6</version>

      <!-- 依赖的类型 -->
      <type>jar</type>


      <!-- 项目如果要使用某个框架或依赖,需要把相关jar包引用到classpath中,maven项目提供了三个classpath:编译、测试、运行 -->
      <!-- 依赖的范围用于控制依赖于三种classpath关系的,包括:compile、provided、runtime、test、system、import -->
      <!-- 
        compile:默认范围,编译、测试、运行都有效
        provided:编译和测试有效,最后运行不会被加入
        runtime:在测试和运行的时候有效,编译不会被加入,比如jdbc驱动jar
        test:测试阶段有效,比如junit
        system:与provided一致,编译和测试阶段有效,但与系统关联,可移植性差
        import:导入的范围,它只是用在dependencyManagement中,表示从其它的pom中导入dependency的配置
       -->
      <!-- 表示当前依赖只能在测试代码中引用使用,在主代码中引用使用则报错 -->
      <scope>test</scope>


      <!-- 排除依赖传递列表,比如A依赖BB依赖C,但是A并没有使用C的功能,可以把C排除-->
      <exclusions>
        <exclusion></exclusion>
      </exclusions>
    </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <!-- 主动设置禁止自己被传递,只在当前项目中使用 -->
            <optional>true</optional>
        </dependency>

    <dependency>
        <groupId>net.sf.json-lib</groupId>
        <artifactId>json-lib</artifactId>
        <!-- 在相同版本下针对不同的环境或者jdk使用的jar,如果配置了这个元素,则会将这个元素名在加在最后来查找相应的jar,
        具体解释查看:http://www.cnblogs.com/lovingprince/archive/2010/09/19/2166273.html -->
        <classifier>jdk15</classifier>
        <version>2.4</version>
    </dependency>
  </dependencies>

  <!-- 使用dependencyManagement标签管理依赖,实际管理的是依赖的版本号,让
所有子项目中引用对应依赖而不用显式的列出版本号;
依赖并不会在当前项目引入 -->
  <dependencyManagement>
    <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>${junit.version}</version>      
        </dependency>
    </dependencies>
  </dependencyManagement>

  <!-- 构建插件 -->
  <build>
    <!-- 
        Maven定制化打包后的包名
        Maven默认的包名为:<finalName>${project.artifactId}-${project.version}</finalName>
        定制化想要的包名,如加上时间戳:<finalName>${project.artifactId}-${maven.build.timestamp}</finalName>
    -->
    <finalName>myProject</finalName>  

    <!-- 将src/main/java目录下src/main/resources目录下适配通配符的文件也打包打进去.因为默认src/main/java下打包时只有class文件,src/main/resources下打包时将各种xml,properites,xsd文件等打包jar或者war里面,防止遗漏部分文件,可以在下面的标签设置 -->
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.*</include>
            </includes>
        </resource>
    </resources>

    <!-- 插件列表 -->
    <plugins>
        <!-- Source attach plugin 发布的包或者打包的时候会将源码也同时打出来 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>2.4</version>
            <executions>
                <execution>
                    <id>attach-sources</id>
                    <phase>package</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <!-- 指定maven编译的jdk版本,如果不指定,maven3默认用jdk 1.5 maven2默认用jdk1.3 --> 
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <!-- 一般而言,target与source是保持一致的,但是,
                有时候为了让程序能在其他版本的jdk中运行(对于低版本目标jdk,源代码中不能使用低版本jdk中不支持的语法),
                会存在target不同于source的情况 -->                    
                <source>1.8</source> <!-- 源代码使用的JDK版本 -->                                                                                             
                <target>1.8</target> <!-- 需要生成的目标class文件的编译版本 -->                                                                                     
                <encoding>UTF-8</encoding><!-- 字符集编码 -->
                <skipTests>true</skipTests><!-- 跳过测试 -->                                                                             
                <verbose>true</verbose>
                <showWarnings>true</showWarnings>                                                                                                               
                <fork>true</fork><!-- 要使compilerVersion标签生效,还需要将fork设为true,用于明确表示编译版本配置的可用 -->                                                        
                <executable><!-- path-to-javac --></executable><!-- 使用指定的javac命令,例如:<executable>${JAVA_1_4_HOME}/bin/javac</executable> -->           
                <compilerVersion>1.3</compilerVersion><!-- 指定插件将使用的编译器的版本 -->                                                                         
                <meminitial>128m</meminitial><!-- 编译器使用的初始内存 -->                                                                                      
                <maxmem>512m</maxmem><!-- 编译器使用的最大内存 -->                                                                                              
                <compilerArgument>-verbose -bootclasspath ${java.home}\lib\rt.jar</compilerArgument><!-- 这个选项用来传递编译器自身不包含但是却支持的参数选项 -->               
            </configuration>
        </plugin>

        <!-- The configuration of maven-assembly-plugin; 其中设计的package.xml和pom.xml是同级目录结构文件,文件内容见下面的package.xml文件 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <id>make-assembly-platform</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <descriptors>
                            <descriptor>package.xml</descriptor>
                        </descriptors>
                        <finalName>patch</finalName>
                        <appendAssemblyId>false</appendAssemblyId>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <!-- findbugs -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
            <configuration>
                <!-- <excludeFilterFile>tools/findbugs/findbugs-exclude.xml</excludeFilterFile> -->
                <threshold>High</threshold>
                <effort>Default</effort>
                <findbugsXmlOutput>true</findbugsXmlOutput>
                <findbugsXmlOutputDirectory>target/site/findbugs</findbugsXmlOutputDirectory>
            </configuration>
        </plugin>       

    </plugins>

    <!-- 插件管理列表,与dependencyManagement标签作用相似,管理插件版本号,让子项目继承使用 -->
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <!-- 插件扩展配置 -->
                <!-- 更详细的例子:http://my.oschina.net/zh119893/blog/276090 -->
                <configuration>
                    <!-- 源代码编译版本 -->
                    <source>1.7</source>
                    <!-- 目标平台编译版本 -->
                    <target>1.7</target>
                    <!-- 设置编译字符集编码 -->
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>

        </plugins>
    </pluginManagement>
  </build>
</project>

二、package.xml文件

<assembly>  
    <id></id>
    <!-- 最终打包成一个用于发布的zip文件 -->  
    <formats>  
        <format>dir</format>  
    </formats>  
    <!-- 将文件或目录直接放在根目录下 -->
   <includeBaseDirectory>false</includeBaseDirectory>
    <!-- Adds dependencies to zip package under lib directory -->  
    <dependencySets>  
        <dependencySet>  
            <!--  
               不使用项目的artifact,第三方jar不要解压,打包进zip文件的lib目录  
           -->  
           <!-- false表示不将本工程对应的jar放进lib目录下 -->
            <useProjectArtifact>false</useProjectArtifact>  
            <outputDirectory>/bin/lib</outputDirectory>  
            <unpack>false</unpack> 
            <scope>runtime</scope> 
        </dependencySet>  
    </dependencySets>  

    <fileSets>  
        <fileSet>  
            <directory>${project.basedir}/shell</directory>  
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>*.*</include>
                <include>*</include>
            </includes>
        </fileSet>
         <fileSet>  
            <directory>${project.build.directory}/classes</directory> 
            <outputDirectory>/bin</outputDirectory>
            <includes>
                <include>**/*.*</include>
            </includes>
        </fileSet>
    </fileSets>  
</assembly>  

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由半码博客整理,本文链接:https://www.bmabk.com/index.php/post/106303.html

(0)

相关推荐

半码博客——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!