命令行中带参数指定${}变量值

<build>

<resources>

<resource>

<directory>src/main/resources</directory>

<filtering>true</filtering>

</resource>

</resources>

<plugins>

<!-- 资源文件拷贝插件,处理资源文件 -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-resources-plugin</artifactId>

<version>3.0.1</version><!--$NO-MVN-MAN-VER$ -->

<configuration>

<encoding>UTF-8</encoding>

<nonFilteredFileExtensions>

<nonFilteredFileExtension>pdf</nonFilteredFileExtension>

<nonFilteredFileExtension>swf</nonFilteredFileExtension>

</nonFilteredFileExtensions>

</configuration>

</plugin>

</plugins>

</build>

Hello ${name}

jest.urls=${name}

(1)   执行mvn resources:resources -Dname="world"

è

Hello world

jest.urls=world

(2)   执行mvn install -Dname="world"

è

Hello world

jest.urls=world

Properties标签中指定${}变量值

<properties>

<name>my testname</name>

</properties>

<build>

<resources>

<resource>

<directory>src/main/resources</directory>

<filtering>true</filtering>

</resource>

</resources>

<plugins>

<!-- 资源文件拷贝插件,处理资源文件 -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-resources-plugin</artifactId>

<version>3.0.1</version><!--$NO-MVN-MAN-VER$ -->

<configuration>

<encoding>UTF-8</encoding>

<nonFilteredFileExtensions>

<nonFilteredFileExtension>pdf</nonFilteredFileExtension>

<nonFilteredFileExtension>swf</nonFilteredFileExtension>

</nonFilteredFileExtensions>

</configuration>

</plugin>

</plugins>

</build>

(1)   执行mvn resources:resources

è

Hello my test name

jest.urls=my testname

(2)   执行mvn install

è

Hello my test name

jest.urls=my testname

properties文件中用<filter>标签过滤

<build>

<resources>

<resource>

<directory>src/main/resources</directory>

<filtering>true</filtering>

</resource>

</resources>

<filters>

<filter>src/main/resources/my-filter-values.properties</filter>

</filters>

<plugins>

<!-- 资源文件拷贝插件,处理资源文件 -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-resources-plugin</artifactId>

<version>3.0.1</version><!--$NO-MVN-MAN-VER$ -->

<configuration>

<encoding>UTF-8</encoding>

<nonFilteredFileExtensions>

<nonFilteredFileExtension>pdf</nonFilteredFileExtension>

<nonFilteredFileExtension>swf</nonFilteredFileExtension>

</nonFilteredFileExtensions>

</configuration>

</plugin>

</plugins>

</build>

my-filter-values.properties

name=mytestingname

(1)   执行mvn resources:resources

è

Hello my testingname

jest.urls=my testingname

(2)   执行mvn install

è

Hello my testingname

jest.urls=my testingname

使用copy-resources copy

<build>

<plugins>

<plugin>

<artifactId>maven-resources-plugin</artifactId>

<version>3.1.0</version>

<executions>

<execution>

<id>copy-resources</id>

<!-- here the phase you need -->

<phase>validate</phase>

<goals>

<goal>copy-resources</goal>

</goals>

<configuration>

<outputDirectory>${basedir}/target/extra-resources</outputDirectory>

<resources>

<resource>

<directory>src/main/resources</directory>

<filtering>true</filtering>

</resource>

</resources>

</configuration>

</execution>

</executions>

</plugin>

</plugins>

</build>

(1)   执行mvn resources:resources

è

Hello my testingname

jest.urls=my testingname

排除文件

<project>

...

<name>MyResources Plugin Practice Project</name>

...

<build>

...

<resources>

<resource>

<directory>src/my-resources</directory>

<includes>

<include>**/*.txt</include>

</includes>

<excludes>

<exclude>**/*test*.*</exclude>

</excludes>

</resource>

...

</resources>

...

</build>

...

</project>

排除二进制文件

<project>

...

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-resources-plugin</artifactId>

<version>3.1.0</version>

<configuration>

...

<nonFilteredFileExtensions>

<nonFilteredFileExtension>pdf</nonFilteredFileExtension>

<nonFilteredFileExtension>swf</nonFilteredFileExtension>

</nonFilteredFileExtensions>

...

</configuration>

</plugin>

</plugins>

...

</build>

...

</project>

禁止过滤  使用<escapeString>

<properties>

<name>my test name</name>

</properties>

<build>

<resources>

<resource>

<directory>src/main/resources</directory>

<filtering>true</filtering>

</resource>

</resources>

<plugins>

<!-- 资源文件拷贝插件,处理资源文件 -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-resources-plugin</artifactId>

<version>3.0.1</version><!--$NO-MVN-MAN-VER$ -->

<configuration>

<escapeString>\</escapeString>

</configuration>

</plugin>

</plugins>

</build>

指定\, 说明\${}的è${},其它照样替换

Hello\${name}

jest.urls=${name}

(1)   执行mvn resources:resources

è

Hello ${name}

jest.urls=my testname

(2)   执行mvn install

è

Hello ${name}

jest.urls=my testname

根据id在不同环境下打对应参数

<build>

<resources>

<resource>

<directory>src/main/resources</directory>

<filtering>true</filtering>

</resource>

</resources>

<plugins>

<!-- 资源文件拷贝插件,处理资源文件 -->

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-resources-plugin</artifactId>

<version>3.0.1</version><!--$NO-MVN-MAN-VER$ -->

<configuration>

<escapeString>\</escapeString>

</configuration>

</plugin>

</plugins>

</build>

<profiles>

<profile>

<id>dev</id>

<properties>

<jest.urls>http://n2:9200,http://n4:9200</jest.urls>

</properties>

<activation>

<activeByDefault>true</activeByDefault>

</activation>

</profile>

<profile>

<id>production</id>

<properties>

<jest.urls>http://192.168.3.241:9200,http://192.168.3.242:9200</jest.urls>

</properties>

</profile>

</profiles>

mvn clean package-DskipTests -Pdev

è

Hello\${jest.urls}

jest.urls=http://n2:9200,http://n4:9200

mvn clean package-DskipTests -Pproduction

è

Hello\${jest.urls}

jest.urls=http://192.168.3.241:9200,http://192.168.3.242:9200

自定义过滤器 Custom resources filters

With version 2.5 you are now able to build your own customresources filter(s).

Your custom resources filter classes must implements org.apache.maven.shared.filtering.MavenResourcesFiltering.

CustomResources Filter Implementation

Your custom resources filter classes must be marked as aPlexus Component. Below a sample with a roleHint itFilter.

1.  /**
2.   * @plexus.component role="org.apache.maven.shared.filtering.MavenResourcesFiltering" 
3.   *                   role-hint="itFilter"
4.   */
5.  public class ItFilter
6.      implements MavenResourcesFiltering

Then you must activate in your build the mojo which willscan javadoc annotations to transform thoses to plexus component metadata.

1.    <plugin>
2.      <groupId>org.codehaus.plexus</groupId>
3.      <artifactId>plexus-maven-plugin</artifactId>
4.      <version>1.3.4</version>
5.      <executions>
6.        <execution>
7.          <goals>
8.            <goal>descriptor</goal>
9.          </goals>
10.      </execution>
11.    </executions>
12.  </plugin>

Dependencydeclaration

Your classes must be available in the maven-resources-pluginclasspath, this can be done with adding your artifact to the plugindependencies.

1.  <project>
2.    ...
3.    <build>
4.      <plugins>
5.        <plugin>
6.          <groupId>org.apache.maven.plugins</groupId>
7.          <artifactId>maven-resources-plugin</artifactId>
8.          <version>3.1.0</version>
9.          <configuration>
10.          ...
11.        </configuration>
12.        <dependencies>
13.          <dependency>
14.            <groupId>custom resources filters artifact groupId</groupId>
15.            <artifactId>custom resources filters artifact artifactId</artifactId>
16.            <version>custom resources filters artifact version</version>
17.          </dependency>
18.        </dependencies>
19.      </plugin>
20.    </plugins>
21.    ...
22.  </build>
23.  ...
24.</project>

Useof your Custom Resource Filter with the maven-resources-plugin

You must now declare you custom filter in the plugin.mavenFilteringHint must respect same syntax as your Plexus Component roleHint.

1.    <plugin>
2.      <groupId>org.apache.maven.plugins</groupId>
3.      <artifactId>maven-resources-plugin</artifactId>
4.      <version>3.1.0</version>
5.      <configuration>
6.        ...
7.        <mavenFilteringHints>
8.          <mavenFilteringHint>itFilter</mavenFilteringHint>
9.        </mavenFilteringHints>
10.     </configuration>
11.     ...
12.   </configuration>
13. </plugin>

maven-resources-plugin使用的更多相关文章

  1. 记录一次maven打包时将test目录下的类打包到jar中,Maven Assembly Plugin的使用

    今天有人问我打包后找不到主类,运行的类写在test中.按照常规,test目录下的文件不会打包到jar包中.(但是我测试一个springboot工程就可以,这里之后再研究) 具体解决如下 第一步:在po ...

  2. springboot项目中使用maven resources

    maven resource 组件可以把pom的变量替换到相关的resouces目录中的资源文件变量 示例项目:内容中心 (文章管理)  生成jar包,生成docker ,生成k8s文件 1.项目结构 ...

  3. 学习Maven之Maven Enforcer Plugin

    1.Maven Enforcer plugin是什么鬼? 在说这个插件是什么前我们先思考这么一个问题:当我们开发人员进入项目组进行开发前,要准备开发环境,而领导总是会强调工具的统一,编译环境的统一.比 ...

  4. [Maven] - Eclipse "maven compiler plugin" 冲突解决

    刚安装最新的Maven 3.2.5,在eclipse中使用maven的Run As->Maven Install,总会提示: Failed to execute goal org.apache. ...

  5. [Apache Maven Shade Plugin] [example] [001] 官方例子:includes-excludes

    链接地址:[Selecting Contents for Uber JAR](http://maven.apache.org/plugins/maven-shade-plugin/examples/i ...

  6. maven jetty plugin

    转载:http://blog.163.com/xueling1231989@126/blog/static/1026408072013101311395492/ 前言: 在 maven 下测试调试时, ...

  7. 施用 maven shade plugin 解决 jar 或类的多版本冲突

    施用 maven shade plugin 解决 jar 或类的多版本冲突   使用 maven shade plugin 解决 jar 或类的多版本冲突java 应用经常会碰到的依赖的三方库出现版本 ...

  8. 解决Maven出现Plugin execution not covered by lifecycle configuration 错误

    http://blog.163.com/xh_ding/blog/static/1939032892015222368827/ 解决Maven出现Plugin execution not covere ...

  9. 关于Error:Maven Resources Compiler: Maven project configuration required for module '项目名' isn't available. Compilation of Maven projects is supported only&

    总是出现Error:Maven Resources Compiler: Maven project configuration required for module '项目名' isn't avai ...

  10. (转)新建maven项目时报错Error:Maven Resources Compiler: Maven project configuration required for module 'XX'解决方法

    转载地址:https://blog.csdn.net/qq784515681/article/details/85070195 在新建maven项目时,Problems中报错: Error:Maven ...

随机推荐

  1. Android 实现两屏幕互相滑动

    Android 实现两屏幕互相滑动 下文来自: http://blog.csdn.net/song_shi_chao/article/details/7081664 ----------------- ...

  2. Base64编码的 换行 转义

    用Base64编码的时候如果出现\n 之类的字符,java中转义. 当字符串过长(一般超过76)时会自动在中间加一个换行符,字符串最后也会加一个换行符.导致和其他模块对接时结果不一致. 解决方法:将  ...

  3. 关于解决Springboot跨域请求的方法

    前言 最近在项目中,由于前后分离,前台项目和后台项目部署的不在一台服务器,就产生了跨域的问题,特此记录下 正文 正常情况下,如果提示: 就可以判断是没有解决跨域的问题了. 在SSM中,我曾经这样解决过 ...

  4. aes加密/解密(转载)

    这篇文章是转载的康奈尔大学ece5760课程里边的一个final project,讲的比较通俗易懂,所以转载过来.附件里边是工程文件,需要注意一点,在用modelsim仿真过程中会出现错误,提示非法引 ...

  5. ballerina 学习九 Client endpoints

    说白了就是连接外部服务的,可以是http jms websocket .... 简单例子 代码 import ballerina/http; import ballerina/log; endpoin ...

  6. Android中关于JNI 的学习(五)在C文件里使用LogCat

    Log是开发过程中.对于我们调试程序非常重要的一个工具,有非常多时候,我们正是通过Log才干够看清楚程序是不是真的依照我们想像中的模式在跑,从而定位到问题所在的地方.而在Android开发中,毫无疑问 ...

  7. Ubuntu 破解密码及用户管理

    Ubuntu 破解密码及用户管理 ubuntu 16.04 破解密码 useradd 实现以下要求 1.ubuntu16.04破解密码 2.创建下面的用户.组和组成员关系 名字为xipudata 的组 ...

  8. 什么是spark(一) 分区以及和MR的区别

    什么是spark,是一个分布式计算平台,或者说是分布式计算引擎,他的职责就是将指定的数据读入到各个node的内存中,然后计算.所以spark是具有泛化性质的,只要数据源是可读入的,读到内存里面之后,处 ...

  9. bzoj5248(洛谷4363)(2018九省联考)一双木棋

    题目:https://www.luogu.org/problemnew/show/P4363 一种考虑状态数的方法:有几个用了k个格子的列,就在第k个0的左边插入几个1: 这也是求不降序列的个数的方法 ...

  10. Nexus搭建私服

    什么是Nexus Nexus是一个强大的Maven仓库管理器,它极大地简化了本地内部仓库的维护和外部仓库的访问. 运行原理 本地仓库与私服处在同一个局域网中,当本地仓库没有资源时,会向私服发起请求获取 ...