这里只记了学习以下博客后,自己做的一个总结。

来源:http://blog.csdn.net/fengchao2016/article/details/72726101

profiles定义了一些不同类型的变量,在这些变量中处于激活状态的才会被真正使用,填充到resources指定的文件中的${},或者filter中书写的路径的${} 里去。

filters定义了一些过滤规则,就是一些文件路径,其下的filter写什么那么就保留什么,剩余的就会被忽视

resources定义了一些目录,也就是被过滤的目录

以上三者共同定义了那些文件需要发布到编译目标目录下,以及文件中的${}的内容应该替换成什么

其它参考:http://jjhpeopl.iteye.com/blog/2325375

最后奉上一个自己做的测试maven pom的项目,pom里面加了一些常见的maven plugin,并且有详细注释内容如下:

里面就3个文件:

Main.java

package com.liuyx;

import java.util.List;

import com.google.common.collect.Lists;

public class Main {

    public Main() {
List<String> l = Lists.newArrayList("hello");
for(String s:l) {
System.out.println(s);
} }
}

config.properties

${a}:${b}

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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.maven</groupId>
<artifactId>testMaven</artifactId>
<version>0.0.1-SNAPSHOT</version> <dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>17.0</version>
</dependency>
</dependencies> <profiles>
<!-- mvn help:active-profiles 查询当前激活的profile -->
<!-- 1、手动激活,直接使用命令指定id mvn package -P test -->
<profile>
<id>test</id>
<properties>
<!-- 这两个可以替换config.properties中的内容 -->
<a>key-test</a>
<b>value-test</b>
<config.name>config.properties</config.name><!-- 这个可以替换filter中的内容 -->
</properties>
<activation>
<!-- 设为默认激活,不设置则默认激活的id为dev -->
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>byfile</id>
<properties>
<a>key-file</a>
<b>value-file</b>
</properties>
<activation>
<!-- 2、根据文件存在来决定是否激活 -->
<file>
<exists>config-file.properties</exists>
</file>
</activation>
</profile>
<profile>
<id>byjdk</id>
<properties>
<a>key-jdk</a>
<b>value-jdk</b>
</properties>
<activation>
<!-- 3、根据jdk环境来决定是否激活 -->
<jdk>1.9</jdk>
</activation>
</profile>
<profile>
<id>byos</id>
<properties>
<a>key-os</a>
<b>value-os</b>
</properties>
<activation>
<!-- 4、根据操作系统环境来决定是否激活 -->
<os>
<name>Windows XP</name>
<family>Windows</family>
<arch>x86</arch>
<version>5.1.2600</version>
</os>
</activation>
</profile>
</profiles> <build>
<!-- 编译后的jar包名称 -->
<finalName>one-maven-test</finalName> <filters> <!-- 指定 filter内容,用来过滤resource下的内容 -->
<filter>src/main/resources/${config.name}</filter>
</filters> <resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<!-- 设为true则用上激活的profile -->
<filtering>true</filtering>
<includes>
<include>**/*.properties</include>
</includes>
<targetPath>${project.build.directory}/config</targetPath>
</resource>
</resources> <!-- 几个常用插件,更多插件请自行搜索 maven plugin -->
<plugins>
<!-- 编译插件,一般用于指定使用的java版本,不过也可以直接在properties中配置
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin> <!-- 用来复制依赖的jar包到指定目录 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<configuration>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
<outputDirectory>
${project.build.directory}/lib
</outputDirectory>
</configuration>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin> <!-- 打成jar包时用来指定MANIFEST.MF文件中的Main class和classpath mainfest等内容 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<archive>
<!-- 是否增加maven描述信息 -->
<addMavenDescriptor>false</addMavenDescriptor> <!-- 批量处理 -->
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.liuyx.Main</mainClass>
<!-- Implementation:实现 -->
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<!-- Specification:规格说明书 -->
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
<!-- 部分内容无法批量处理,手动添加,这里把.和libs/都添加到了 classpath中 -->
<manifestEntries>
<Class-Path>.</Class-Path>
<Class-Path>libs/</Class-Path>
<Permissions>${Permissions}</Permissions>
<Caller-Allowable-Codebase>${Caller-Allowable-Codebase}</Caller-Allowable-Codebase>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>

maven profiles、filters、resources学习笔记 及 常用 plugin demo的更多相关文章

  1. python3.4学习笔记(十) 常用操作符,条件分支和循环实例

    python3.4学习笔记(十) 常用操作符,条件分支和循环实例 #Pyhon常用操作符 c = d = 10 d /= 8 #3.x真正的除法 print(d) #1.25 c //= 8 #用两个 ...

  2. python3.4学习笔记(六) 常用快捷键使用技巧,持续更新

    python3.4学习笔记(六) 常用快捷键使用技巧,持续更新 安装IDLE后鼠标右键点击*.py 文件,可以看到Edit with IDLE 选择这个可以直接打开编辑器.IDLE默认不能显示行号,使 ...

  3. Python学习笔记之常用函数及说明

    Python学习笔记之常用函数及说明 俗话说"好记性不如烂笔头",老祖宗们几千年总结出来的东西还是有些道理的,所以,常用的东西也要记下来,不记不知道,一记吓一跳,乖乖,函数咋这么多 ...

  4. java web jsp学习笔记--概述-常用语法,指令,动作元素,隐式对象,域对象

     JSP学习笔记 1.什么是jsp JSP全称是Java Server Pages,它和servle技术一样,都是SUN公司定义的一种用于开发动态web资源的技术.JSP/Servlet规范.JS ...

  5. git学习笔记:常用命令总结

    本文根据廖雪峰的博客,记录下自己的学习笔记.主要记录常用的命令,包括仓库初始化.添加文件.提交修改.新建分支.内容暂存.分支管理.标签管理等内容. git是分布式版本控制系统. 首先是安装,从官网下载 ...

  6. python自动化测试学习笔记-5常用模块

    上一次学习了os模块,sys模块,json模块,random模块,string模块,time模块,hashlib模块,今天继续学习以下的常用模块: 1.datetime模块 2.pymysql模块(3 ...

  7. [原创]java WEB学习笔记30:Cookie Demo 之显示最近浏览的记录

    本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...

  8. [原创]java WEB学习笔记29:Cookie Demo 之自动登录

    本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...

  9. [Python] Python学习笔记之常用模块总结[持续更新...]

    作为一种极其简单的编程语言,Python目前成为了最炙手可热的几种语言之一.它不仅简单易学,而且它还为用户提供了各种各样的模块,功能强大,无所不能.有利必有弊,学习Python同样有困扰,其中之一就是 ...

随机推荐

  1. 03把IL编译成可执行文件

    1.在记事本中编写IL代码如下: .assembly HelloWorld{} .assembly extern mscorlib{}   .method public static void Mai ...

  2. java 内存溢出 栈溢出的原因与排查方法

     1. 内存溢出的原因是什么?        内存溢出是由于没被引用的对象(垃圾)过多造成JVM没有及时回收,造成的内存溢出.如果出现这种现象可行代码排查: 一)是否App中的类中和引用变量过多使用了 ...

  3. ExtJS GridPanel的ColumnModel 动态加载

    var colM = "company,id,flyline"; var colMArr = colM.split(","); var colLength = ...

  4. 【Codeforces】【#295】【Div.2】

    o(︶︿︶)o 唉跪烂了…… B题由于考虑的不周全WA了3次…… C题由于#include了<cmath>,而我函数声明的是pow(LL a,LL b)但调用的时候 [没!有!把!n!的! ...

  5. 【PAT Advanced Level】1011. World Cup Betting (20)

    简单模拟题,遍历一遍即可.考察输入输出. #include <iostream> #include <string> #include <stdio.h> #inc ...

  6. Pascal VOC & COCO数据集介绍 & 转换

    目录 Pascal VOC & COCO数据集介绍 Pascal VOC数据集介绍 1. JPEGImages 2. Annotations 3. ImageSets 4. Segmentat ...

  7. Android中XML解析-SAX解析

    昨天由于时间比较匆忙只写了Android中的XML解析的Dom方式,这种方式比较方便,很容易理解,最大的不足就是内容多的时候,会消耗内存.SAX(Simple API for XML)是一个解析速度快 ...

  8. ASP.NET与ASP.NET MVC 中Cache的总结

    Cache有多种翻译,可以是高速缓冲存储器,也可以是法国的服装品牌,本文只是简单的谈谈就是ASP.NET 中Cache,做过Web应用程序的都知道,如果网站访问量比较大,系统应用程序可以将那些频繁访问 ...

  9. OpenGL视图--gluPerspective glOrtho glFrustum gluLookAt

    void gluPerspective( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar ) near 和 far 决定了投 ...

  10. centos7 JDK1.8

    安装之前先检查一下系统有没有自带open-jdk rpm -qa |grep java rpm -qa |grep jdk 卸载找出的已安装Java相关rpm文件:rpm -e --nodeps 重新 ...