maven 插件_2 Maven Resources Plugin
来源:互联网 发布:飞鸽传书需要网络吗 编辑:程序博客网 时间:2024/06/14 06:25
http://maven.apache.org/plugins/maven-resources-plugin/
resource插件对资源文件编码处理,资源文件目录指定,资源文件拷贝等功能,最后将资源文件拷贝到一个目录
默认执行方法: mvn resources:resources
如果是copy-resources:执行方法: mvn resources:copy-resources
执行后,将资源文件拷贝到target/classes中
The Resources Plugin has three goals:
- resources:resources 拷贝\src\main\resources文件到输出目录
此goal默认是绑定process-resources life-cycle phase
- resources:testResources 拷贝\src\test\resources文件到输出目录
- 此goal默认是绑定process-resources life-cycle phase
- resources:copy-resources copies resources to an output directory.
This goal requires that you configure the resources to be copied, and specify the outputDirectory
1. 指定资源文件编码方式
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.7</version> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin>2. 指定资源文件路径
默认情况资源文件路径: src\main\resources。可以在effective pom 中 resources配置的路径看到哦
现在我们指定资源路径,就不适用默认的src/main/resource了,可以指定多个资源路径,directory的路径以pom.xml所以路径相对的
例如:
Project|-- pom.xml`-- src `-- my-resources
如下配置
<resources> <resource> <directory>src/my-resources</directory> </resource> </resources>
<build>
<resources> <resource> <directory>resource1</directory> </resource> <resource> <directory>resource2</directory> </resource> <resource> <directory>resource3</directory> </resource> </resources></build>
3. include/exclude 资源文件和目录
<build> ... <resources> <resource> <directory>src/my-resources</directory> <includes> <include>**/*.txt</include> </includes> <excludes> <exclude>**/*test*.*</exclude>
<exclude>**/*.jpeg</exclude>
</excludes> </resource> ... </resources> ... </build>
<exclude>**/*.jpeg</exclude></excludes> </resource> ... </resources> ... </build>
4. 执行mvn resources:resources 将文件默认拷贝到target/classes中,指定拷贝到的目录
设置: <outputDirectory></outputDirectory>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<outputDirectory>${basedir}/target</outputDirectory>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<outputDirectory>${basedir}/target</outputDirectory>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
也可以放在
<build>
<outputDirectory>${basedir}/target</outputDirectory>
</build>
查看effective pom 里面可以看到哦
5. fliter 使用: 资源文件可以使用变量,通过filter处理变量 ${}
加上: <filtering>true</filtering>,才对此资源目录下的文件中${} 进行处理。
如果不加filtering,则此文件${}不会处理哦
<resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource>
那么${}中的值可以有3中方式
举例: 资源文件中有${name} 和${age}
1>
6. copy resources 拷贝文件 mvn resources:resources -Dname="world" -Dage="12"
2><project> ... <properties> <name>world</name><age>12</age></properties> ...</project>3> 放在文件里面<build> ... <filters> <filter>my-filter-values.properties</filter> </filters> ... </build>my-filter-values.properties 文件内容:name=worldage=12
<plugin> <artifactId>maven-resources-plugin</artifactId> <version>2.7</version> <executions> <execution> <id>copy-resources</id> <!-- 可以是其他阶段--> <phase>validate</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${basedir}/target/extra-resources</outputDirectory> <resources> <resource> <directory>src/non-packaged-resources</directory> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin> </plugins>
执行:mvn validate 。执行validate阶段时会操作copy。
对不同环境无法通过此方式来拷贝不同环境的文件。所以建议使用war中的
0 0
- maven 插件_2 Maven Resources Plugin
- maven resources plugin 2.5插件找不到
- maven-resources-plugin
- MAVEN ERROR maven-resources-plugin
- maven-resources-plugin:2.6:resources (default-resources)
- Eclipse maven-resources-plugin 错误
- maven的resources插件
- cobertura-maven-plugin插件 maven
- maven插件 buildnumber-maven-plugin
- Maven插件:maven-javadoc-plugin
- eclipse maven plugin 插件
- maven-surefire-plugin插件
- maven-compiler-plugin插件
- 插件maven-compiler-plugin
- Maven-assembly-plugin插件
- maven-antrun-plugin插件
- eclipse安装maven插件开发WEB项目,解决错误:Failure to transfer org.apache.maven.plugins:maven-resources-plugin:pom
- maven-resources-plugin问题报错
- 标准库类型string
- 打开适配器并捕获数据包
- spring官网
- world break
- 解决XCode7.1 上无法安装 Alcatraz PackageManager
- maven 插件_2 Maven Resources Plugin
- 20.12. smtplib — SMTP protocol client(SMTP 协议 客户端)
- LaTeX插入图片时,图总是置顶的解决办法
- malloc内存管理器内存不释放的解决方法
- Objective-C中的实例方法、类方法、Category、Protocol
- 欢迎使用CSDN-markdown编辑器
- 多线程学习三(synchronized和Lock)
- java web session有效时间单位问题
- 硬盘MBR详细介绍