maven内置变量

  1. ${basedir}表示项目根目录,即包含pom.xml文件的目录;
  2.  
  3. ${version}表示项目版本;
  4.  
  5. ${project.basedir}同${basedir};
  6.  
  7. ${project.baseUri}表示项目文件地址;
  8.  
  9. ${maven.build.timestamp}表示项目构件开始时间;
  10.  
  11. ${maven.build.timestamp.format}表示属性${maven.build.timestamp}的展示格式,默认值为yyyyMMdd-HHmm,可自定义其格式,其类型可参考java.text.SimpleDateFormat

 ${project.build.directory}表示主源码路径;

  1.  

 ${project.build.sourceEncoding}表示主源码的编码格式;

  1.  

 ${project.build.sourceDirectory}表示主源码路径;

  1.  

 ${project.build.finalName}表示输出文件名称;

  1.  

${project.version}表示项目版本,与${version}相同;

  1.  
  • ${project.xxx} 当前pom文件的任意节点的内容
  • ${env.xxx} 获取系统环境变量。
  • ${settings.xxx} 指代了settings.xml中对应元素的值。
  1.  

1.maven-compiler-plugin

  设置maven编译的jdk版本,maven3默认用jdk1.5,maven2默认用jdk1.3

  1. <plugin>
  2. <groupId>org.apache.maven.plugins</groupId>
  3. <artifactId>maven-compiler-plugin</artifactId>
  4. <version>3.1</version>
  5. <configuration>
  6. <source>1.8</source> <!-- 源代码使用的JDK版本 -->
  7. <target>1.8</target> <!-- 需要生成的目标class文件的编译版本 -->
  8. <encoding>UTF-8</encoding><!-- 字符集编码 -->
  9. <skipTests>true</skipTests><!-- 跳过测试 -->
  10. </configuration>
  11. </plugin>

2.maven-jar-plugin

  1. <!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
  2. <plugin>
  3. <groupId>org.apache.maven.plugins</groupId>
  4. <artifactId>maven-jar-plugin</artifactId>
  5. <configuration>
  6. <classesDirectory>target/classes/</classesDirectory>
  7. <archive>
  8. <manifest>
  9. <mainClass>com.alibaba.dubbo.container.Main</mainClass>
  10. <!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 -->
  11. <!--自动加载META-INF/spring目录下的所有Spring配置-->
  12. <useUniqueVersions>false</useUniqueVersions>
  13. <addClasspath>true</addClasspath>
  14. <classpathPrefix>lib/</classpathPrefix>
  15. </manifest>
  16. <manifestEntries>
  17. <Class-Path>.</Class-Path>
  18. </manifestEntries>
  19. </archive>
  20. </configuration>
  21. </plugin>

3.maven-source-plugin

打包源码

注意:在多项目构建中,将source-plugin置于顶层或parent的pom中并不会发挥作用,必须置于具体项目的pom中。

  1. <plugin>
  2. <groupId>org.apache.maven.plugins</groupId>
  3. <artifactId>maven-source-plugin</artifactId>
  4. <executions>
  5. <execution>
  6. <id>attach-sources</id>
  7. <goals>
  8. <goal>jar</goal>
  9. </goals>
  10. </execution>
  11. </executions>
  12. </plugin>

4.maven-resource-plugin

说明:该插件处理项目的资源文件拷贝到输出目录。可以分别处理main resources 和 test resources。

  1. <plugin>
  2. <groupId>org.apache.maven.plugins</groupId>
  3. <artifactId>maven-resources-plugin</artifactId>
  4. <version>3.0.1</version>
  5. <configuration>
  6. <encoding>UTF-8</encoding>
  7. </configuration>
  8. </plugin>

5.maven-dependency-plugin

自动拷贝jar包到target目录

  1. <!-- 依赖插件 -->
  2. <plugin>
  3. <groupId>org.apache.maven.plugins</groupId>
  4. <artifactId>maven-dependency-plugin</artifactId>
  5. <version>2.6</version>
  6. <executions>
  7. <execution>
  8. <id>copy-dependencies</id>
  9. <phase>compile</phase>
  10. <goals>
  11. <goal>copy-dependencies</goal>
  12. </goals>
  13. <configuration>
  14. <!-- ${project.build.directory}为Maven内置变量,缺省为target -->
  15. <outputDirectory>${project.build.directory}/lib</outputDirectory>
  16. <!-- 表示是否不包含间接依赖的包 -->
  17. <excludeTransitive>false</excludeTransitive>
  18. <!-- 表示复制的jar文件去掉版本信息 -->
  19. <stripVersion>true</stripVersion>
  20. </configuration>
  21. </execution>
  22. </executions>
  23. </plugin>

6.maven-assembly-plugin

该插件允许用户整合项目的输出,包括依赖,模块,网站文档和其他文档到一个单独的文档,即可用定制化打包。

创建的文档格式包括:zip, tar, tar.gz(tgz), gar.bz2(tbgz2), jar, dir,war 等等。四种预定义的描述器可用:bin, jar-with-dependencies, src, project.

  1.  
  1. <plugin>
  2. <artifactId>maven-assembly-plugin</artifactId>
  3. <version>3.0.0</version>
  4. <configuration>
  5. <descriptorRefs>
  6. <descriptorRef>jar-with-dependencies</descriptorRef>
  7. </descriptorRefs>
  8. </configuration>
  9. <executions>
  10. <execution>
  11. <id>make-assembly</id> <!-- this is used for inheritance merges -->
  12. <phase>package</phase> <!-- bind to the packaging phase -->
  13. <goals>
  14. <goal>single</goal>
  15. </goals>
  16. </execution>
  17. </executions>
  18. </plugin>
  1. <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
  4. <id>bin</id>
  5. <formats>
  6. <format>tar.gz</format>
  7. <format>tar.bz2</format>
  8. <format>zip</format>
  9. </formats>
  10. <fileSets>
  11. <fileSet>
  12. <directory>${project.basedir}</directory>
  13. <outputDirectory>/</outputDirectory>
  14. <includes>
  15. <include>README*</include>
  16. <include>LICENSE*</include>
  17. <include>NOTICE*</include>
  18. </includes>
  19. </fileSet>
  20. <fileSet>
  21. <directory>${project.build.directory}</directory>
  22. <outputDirectory>/</outputDirectory>
  23. <includes>
  24. <include>*.jar</include>
  25. </includes>
  26. </fileSet>
  27. <fileSet>
  28. <directory>${project.build.directory}/site</directory>
  29. <outputDirectory>docs</outputDirectory>
  30. </fileSet>
  31. </fileSets>
  32. </assembly>
  1. <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
  4. <!-- TODO: a jarjar format would be better -->
  5. <id>jar-with-dependencies</id>
  6. <formats>
  7. <format>jar</format>
  8. </formats>
  9. <includeBaseDirectory>false</includeBaseDirectory>
  10. <dependencySets>
  11. <dependencySet>
  12. <outputDirectory>/</outputDirectory>
  13. <useProjectArtifact>true</useProjectArtifact>
  14. <unpack>true</unpack>
  15. <scope>runtime</scope>
  16. </dependencySet>
  17. </dependencySets>
  18. </assembly>
  1. <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
  4. <id>src</id>
  5. <formats>
  6. <format>tar.gz</format>
  7. <format>tar.bz2</format>
  8. <format>zip</format>
  9. </formats>
  10. <fileSets>
  11. <fileSet>
  12. <directory>${project.basedir}</directory>
  13. <includes>
  14. <include>README*</include>
  15. <include>LICENSE*</include>
  16. <include>NOTICE*</include>
  17. <include>pom.xml</include>
  18. </includes>
  19. <useDefaultExcludes>true</useDefaultExcludes>
  20. </fileSet>
  21. <fileSet>
  22. <directory>${project.basedir}/src</directory>
  23. <useDefaultExcludes>true</useDefaultExcludes>
  24. </fileSet>
  25. </fileSets>
  26. </assembly>

Maven常用插件整理的更多相关文章

  1. idea教程视频以及常用插件整理

    最近在同事的强烈安利下把eclipse换成idea了,本以为需要经历一个艰难的过渡期,谁知道不到3天就深感回不去了. 哎,只能说有时候人的惰性是多么可怕! idea实在是太太太强大了. 不要再问原因. ...

  2. maven常用插件pom配置

    一.问题描述: 部署一个maven打包项目时,jar包,依赖lib包全部手动上传至服务器,然后用maven部署报错:Exception in thread "main" java. ...

  3. Maven常用插件

    maven利用各种插件来管理构建项目,本文记录下工作中常用到的插件及使用方法.每个插件都会提供多个目标(goal),用于标示任务.各插件配置在pom.xml里,如下: <build> [. ...

  4. maven常用插件总结

    maven本质上是一个插件框架,几乎所有的功能都是通过各种各样的插件来实现的.maven默认会依据项目类型自动把构建时的各阶段(Lifecycle和phase)自动绑定(Lifecycle Mappi ...

  5. maven常用插件配置详解

    常用插件配置详解Java代码    <!-- 全局属性配置 --> <properties> <project.build.name>tools</proje ...

  6. Maven常用插件简单配置

    好久不见,甚是想念.一日不见,如隔三秋. 从春节到现在已经很久没有回归博客园了,今天回来温习一下maven常用的一些插件的配置,学东西一个很简单的诀窍就是重复重复再重复,这样一定能把知识掌握的很牢靠. ...

  7. Visual Studio Code 常用插件整理

    常用插件说明: 一.HTML Snippets 超级使用且初级的H5代码片段以及提示 二.HTML CSS Support  让HTML标签上写class智能提示当前项目所支持的样式 三.Debugg ...

  8. ionic2——开发利器之Visual Studio Code 常用插件整理

    1.VsCode官方插件地址: http://code.visualstudio.com/docs 2.使用方法,可以在官网中搜索需要的插件或者在VsCode的“”扩展“”中搜索需要的插件 添加方法使 ...

  9. IDEA常用插件整理

    1. 集成步骤 1.1. 配置环境变量 变量名:CMDER_ROOT 变量值:D:\Tool\cmder 1.2. IDEA中设置 settings->Tool->Terminal She ...

随机推荐

  1. day05.2-Vim编辑器

    一. 安装Vim编辑器和打开新建文件      安装Vim编辑器:apt-get   install   Vim 新建与打开Vim文件:vim   文件名 二. Vim编辑器三种模式的使用与切换 指令 ...

  2. Spring IOC机制之使用注解配置bean

    一. 通过注解配置bean 1.1       概述 相对于XML方式而言,通过注解的方式配置bean更加简洁和优雅,而且和MVC组件化开发的理念十分契合,是开发中常用的使用方式. 1.2       ...

  3. Eclipse 创建Maven 项目

    https://www.cnblogs.com/noteless/p/5213075.html

  4. Visual Studio 2017 Key激活码

     Microsoft Visual Studio Enterprise 2017 企业版 KEY:NJVYC-BMHX2-G77MM-4XJMR-6Q8QFMicrosoft Visual Studi ...

  5. MySQL 关联查询  外连接 { LEFT| RIGHT } JOIN

    左外连接: (以左表为基准)两张表做连接的时候,在连接条件不匹配的时候留下左表中的数据,而右表中的数据以NULL填充例:使用左连接把学生的数据全取出来,该学生没有学院信息的用NULL填充 mysql& ...

  6. C语言中Extern用法

    extern用在变量或函数的声明前,用来说明“此变量/函数是在别处定义的,要在此处引用”. extern修饰变量的声明. 举例:若a.c中需引用b.c中的变量int v,可以在a.c中声明extern ...

  7. CF C. Three displays(DP+思维)

    http://codeforces.com/contest/987/problem/C 题意:给你两个n的序列要你根据第一个序列(严格单调递增的方式)在第二个序列里找3个数加起来,输出最小的一个. 思 ...

  8. Python入门8文件处理

    文件处理文本模式name = input("请输入用户名:").strip()with open("a.txt","wt",encoding ...

  9. 小白零基础C#学习笔记

    一.概述 1..Net 1)..Net平台 2)..Net Frameword框架 说明:是.Net平台中不可缺少的一部分,提供了一个稳定的运行环境来保证.Net平台开发的各种应用能够正常运转. 2. ...

  10. JavaScript中使用ActiveXObject操作本地文件夹的方法

    转载地址    http://www.jb51.net/article/48538.htm 在Windows平台上, js可以调用很多Windows提供的ActivexObject,本文就使用js来实 ...