Maven常用插件整理
maven内置变量
- ${basedir}表示项目根目录,即包含pom.xml文件的目录;
- ${version}表示项目版本;
- ${project.basedir}同${basedir};
- ${project.baseUri}表示项目文件地址;
- ${maven.build.timestamp}表示项目构件开始时间;
- ${maven.build.timestamp.format}表示属性${maven.build.timestamp}的展示格式,默认值为yyyyMMdd-HHmm,可自定义其格式,其类型可参考java.text.SimpleDateFormat。
${project.build.directory}表示主源码路径;
${project.build.sourceEncoding}表示主源码的编码格式;
${project.build.sourceDirectory}表示主源码路径;
${project.build.finalName}表示输出文件名称;
${project.version}表示项目版本,与${version}相同;
- ${project.xxx} 当前pom文件的任意节点的内容
- ${env.xxx} 获取系统环境变量。
- ${settings.xxx} 指代了settings.xml中对应元素的值。
1.maven-compiler-plugin
设置maven编译的jdk版本,maven3默认用jdk1.5,maven2默认用jdk1.3
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.1</version>
- <configuration>
- <source>1.8</source> <!-- 源代码使用的JDK版本 -->
- <target>1.8</target> <!-- 需要生成的目标class文件的编译版本 -->
- <encoding>UTF-8</encoding><!-- 字符集编码 -->
- <skipTests>true</skipTests><!-- 跳过测试 -->
- </configuration>
- </plugin>
2.maven-jar-plugin
- <!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <configuration>
- <classesDirectory>target/classes/</classesDirectory>
- <archive>
- <manifest>
- <mainClass>com.alibaba.dubbo.container.Main</mainClass>
- <!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 -->
- <!--自动加载META-INF/spring目录下的所有Spring配置-->
- <useUniqueVersions>false</useUniqueVersions>
- <addClasspath>true</addClasspath>
- <classpathPrefix>lib/</classpathPrefix>
- </manifest>
- <manifestEntries>
- <Class-Path>.</Class-Path>
- </manifestEntries>
- </archive>
- </configuration>
- </plugin>
3.maven-source-plugin
打包源码
注意:在多项目构建中,将source-plugin置于顶层或parent的pom中并不会发挥作用,必须置于具体项目的pom中。
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-source-plugin</artifactId>
- <executions>
- <execution>
- <id>attach-sources</id>
- <goals>
- <goal>jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
4.maven-resource-plugin
说明:该插件处理项目的资源文件拷贝到输出目录。可以分别处理main resources 和 test resources。
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <version>3.0.1</version>
- <configuration>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
5.maven-dependency-plugin
自动拷贝jar包到target目录
- <!-- 依赖插件 -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <version>2.6</version>
- <executions>
- <execution>
- <id>copy-dependencies</id>
- <phase>compile</phase>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- <configuration>
- <!-- ${project.build.directory}为Maven内置变量,缺省为target -->
- <outputDirectory>${project.build.directory}/lib</outputDirectory>
- <!-- 表示是否不包含间接依赖的包 -->
- <excludeTransitive>false</excludeTransitive>
- <!-- 表示复制的jar文件去掉版本信息 -->
- <stripVersion>true</stripVersion>
- </configuration>
- </execution>
- </executions>
- </plugin>
6.maven-assembly-plugin
该插件允许用户整合项目的输出,包括依赖,模块,网站文档和其他文档到一个单独的文档,即可用定制化打包。
创建的文档格式包括:zip, tar, tar.gz(tgz), gar.bz2(tbgz2), jar, dir,war 等等。四种预定义的描述器可用:bin, jar-with-dependencies, src, project.
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <version>3.0.0</version>
- <configuration>
- <descriptorRefs>
- <descriptorRef>jar-with-dependencies</descriptorRef>
- </descriptorRefs>
- </configuration>
- <executions>
- <execution>
- <id>make-assembly</id> <!-- this is used for inheritance merges -->
- <phase>package</phase> <!-- bind to the packaging phase -->
- <goals>
- <goal>single</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
- <id>bin</id>
- <formats>
- <format>tar.gz</format>
- <format>tar.bz2</format>
- <format>zip</format>
- </formats>
- <fileSets>
- <fileSet>
- <directory>${project.basedir}</directory>
- <outputDirectory>/</outputDirectory>
- <includes>
- <include>README*</include>
- <include>LICENSE*</include>
- <include>NOTICE*</include>
- </includes>
- </fileSet>
- <fileSet>
- <directory>${project.build.directory}</directory>
- <outputDirectory>/</outputDirectory>
- <includes>
- <include>*.jar</include>
- </includes>
- </fileSet>
- <fileSet>
- <directory>${project.build.directory}/site</directory>
- <outputDirectory>docs</outputDirectory>
- </fileSet>
- </fileSets>
- </assembly>
- <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
- <!-- TODO: a jarjar format would be better -->
- <id>jar-with-dependencies</id>
- <formats>
- <format>jar</format>
- </formats>
- <includeBaseDirectory>false</includeBaseDirectory>
- <dependencySets>
- <dependencySet>
- <outputDirectory>/</outputDirectory>
- <useProjectArtifact>true</useProjectArtifact>
- <unpack>true</unpack>
- <scope>runtime</scope>
- </dependencySet>
- </dependencySets>
- </assembly>
- <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
- <id>src</id>
- <formats>
- <format>tar.gz</format>
- <format>tar.bz2</format>
- <format>zip</format>
- </formats>
- <fileSets>
- <fileSet>
- <directory>${project.basedir}</directory>
- <includes>
- <include>README*</include>
- <include>LICENSE*</include>
- <include>NOTICE*</include>
- <include>pom.xml</include>
- </includes>
- <useDefaultExcludes>true</useDefaultExcludes>
- </fileSet>
- <fileSet>
- <directory>${project.basedir}/src</directory>
- <useDefaultExcludes>true</useDefaultExcludes>
- </fileSet>
- </fileSets>
- </assembly>
Maven常用插件整理的更多相关文章
- idea教程视频以及常用插件整理
最近在同事的强烈安利下把eclipse换成idea了,本以为需要经历一个艰难的过渡期,谁知道不到3天就深感回不去了. 哎,只能说有时候人的惰性是多么可怕! idea实在是太太太强大了. 不要再问原因. ...
- maven常用插件pom配置
一.问题描述: 部署一个maven打包项目时,jar包,依赖lib包全部手动上传至服务器,然后用maven部署报错:Exception in thread "main" java. ...
- Maven常用插件
maven利用各种插件来管理构建项目,本文记录下工作中常用到的插件及使用方法.每个插件都会提供多个目标(goal),用于标示任务.各插件配置在pom.xml里,如下: <build> [. ...
- maven常用插件总结
maven本质上是一个插件框架,几乎所有的功能都是通过各种各样的插件来实现的.maven默认会依据项目类型自动把构建时的各阶段(Lifecycle和phase)自动绑定(Lifecycle Mappi ...
- maven常用插件配置详解
常用插件配置详解Java代码 <!-- 全局属性配置 --> <properties> <project.build.name>tools</proje ...
- Maven常用插件简单配置
好久不见,甚是想念.一日不见,如隔三秋. 从春节到现在已经很久没有回归博客园了,今天回来温习一下maven常用的一些插件的配置,学东西一个很简单的诀窍就是重复重复再重复,这样一定能把知识掌握的很牢靠. ...
- Visual Studio Code 常用插件整理
常用插件说明: 一.HTML Snippets 超级使用且初级的H5代码片段以及提示 二.HTML CSS Support 让HTML标签上写class智能提示当前项目所支持的样式 三.Debugg ...
- ionic2——开发利器之Visual Studio Code 常用插件整理
1.VsCode官方插件地址: http://code.visualstudio.com/docs 2.使用方法,可以在官网中搜索需要的插件或者在VsCode的“”扩展“”中搜索需要的插件 添加方法使 ...
- IDEA常用插件整理
1. 集成步骤 1.1. 配置环境变量 变量名:CMDER_ROOT 变量值:D:\Tool\cmder 1.2. IDEA中设置 settings->Tool->Terminal She ...
随机推荐
- day05.2-Vim编辑器
一. 安装Vim编辑器和打开新建文件 安装Vim编辑器:apt-get install Vim 新建与打开Vim文件:vim 文件名 二. Vim编辑器三种模式的使用与切换 指令 ...
- Spring IOC机制之使用注解配置bean
一. 通过注解配置bean 1.1 概述 相对于XML方式而言,通过注解的方式配置bean更加简洁和优雅,而且和MVC组件化开发的理念十分契合,是开发中常用的使用方式. 1.2 ...
- Eclipse 创建Maven 项目
https://www.cnblogs.com/noteless/p/5213075.html
- Visual Studio 2017 Key激活码
Microsoft Visual Studio Enterprise 2017 企业版 KEY:NJVYC-BMHX2-G77MM-4XJMR-6Q8QFMicrosoft Visual Studi ...
- MySQL 关联查询 外连接 { LEFT| RIGHT } JOIN
左外连接: (以左表为基准)两张表做连接的时候,在连接条件不匹配的时候留下左表中的数据,而右表中的数据以NULL填充例:使用左连接把学生的数据全取出来,该学生没有学院信息的用NULL填充 mysql& ...
- C语言中Extern用法
extern用在变量或函数的声明前,用来说明“此变量/函数是在别处定义的,要在此处引用”. extern修饰变量的声明. 举例:若a.c中需引用b.c中的变量int v,可以在a.c中声明extern ...
- CF C. Three displays(DP+思维)
http://codeforces.com/contest/987/problem/C 题意:给你两个n的序列要你根据第一个序列(严格单调递增的方式)在第二个序列里找3个数加起来,输出最小的一个. 思 ...
- Python入门8文件处理
文件处理文本模式name = input("请输入用户名:").strip()with open("a.txt","wt",encoding ...
- 小白零基础C#学习笔记
一.概述 1..Net 1)..Net平台 2)..Net Frameword框架 说明:是.Net平台中不可缺少的一部分,提供了一个稳定的运行环境来保证.Net平台开发的各种应用能够正常运转. 2. ...
- JavaScript中使用ActiveXObject操作本地文件夹的方法
转载地址 http://www.jb51.net/article/48538.htm 在Windows平台上, js可以调用很多Windows提供的ActivexObject,本文就使用js来实 ...