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

来源: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. 报错:对一个或多个实体的验证失败。有关详细信息,请参阅“EntityValidationErrors”属性

    当使用Entity Framework,并且把领域模型的某个字段设置成不能为null,但在保存.更新的时候,如果领域模型的该字段为null了,就会报如上错误. 解决方法:给领域模型不能为null的字段 ...

  2. Spring DAO vs Spring ORM vs Spring JDBC

    Pat 的疑惑 最近关注于 Spring 提供的数据访问技术,对于 Spring 相关的这几个项目有何不同我不是太明白: Spring-DAO (http://docs.spring.io/sprin ...

  3. DevExpress RichEditControl 上下翻页功能 z

    /// <summary> /// 翻页 /// </summary> /// <param name="isPre"></param&g ...

  4. .NET:CLR via C# The Interlocked Anything Pattern

    Many people look at the Interlocked methods and wonder why Microsoft doesn't create a richer set of ...

  5. 使用 SVWebViewController 推出浏览器控制器

    SVWebViewController 简单翻译 https://github.com/samvermette/SVWebViewController SVWebViewController is a ...

  6. 使用命名参数处理 CallableStatement

    简介:JDBC 中的语句处理 在 JDBC 应用程序中,JDBC 语句对象用于将 SQL 语句发送到数据库服务器.一个语句对象与一个连接相关联,应用程序与数据库服务器之间的通信由语句对象来处理. JD ...

  7. Windows 7系统垃圾清理自写程序

    系统清理.bat @echo off color 0a title windows7系统垃圾清理--- echo ★☆ ★☆ ★☆ ★☆ ★☆★☆★☆ ★☆ ★☆ ★☆ ★☆★ echo ★☆ ★☆ ...

  8. Flume-NG一些注意事项(转)

    原文链接:记Flume-NG一些注意事项 这里只考虑flume本身的一些东西,对于JVM.HDFS.HBase等得暂不涉及.... 一.关于Source: 1.spool-source:适合静态文件, ...

  9. [转]聊聊技术选型 - Angular2 vs Vue2

    转载:https://juejin.im/post/58cab85b44d9040069f38f7a "Come, and take choice of all my library, An ...

  10. 第九章 Redis过期策略

    注:本文主要参考自<Redis设计与实现> 1.设置过期时间 expire key time(以秒为单位)--这是最常用的方式 setex(String key, int seconds, ...