我使用maven-resource-plugin来过滤我的 maven 项目中的一些资源。在我的父项目中,我有:
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
在一个子项目中,我有一个test.properties文件,它是一个普通的java 属性文件,默认编码 = ISO-8859-1。该文件包含:
aboutText=Version ${project.version} © 2012 blabla
为了确保此文件正确过滤,我已将 maven-resource-plugin 拆分为单独的执行,每个执行都有其编码:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>ico</nonFilteredFileExtension>
<nonFilteredFileExtension>jar</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
<executions>
<execution>
<id>filter-properties-files</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<!-- java properties files are encoded in ISO-8859-1 so when
filtering those files we stick with that encoding. -->
<encoding>ISO-8859-1</encoding>
<outputDirectory>${basedir}/after</outputDirectory>
<resources>
<resource>
<filtering>true</filtering>
<directory>${basedir}/before</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>filter-non-properties-files</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
<outputDirectory>${basedir}/after</outputDirectory>
<resources>
<resource>
<filtering>true</filtering>
<directory>${basedir}/before</directory>
<includes>
<include>**/*.product</include>
<include>**/*.inf</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
这似乎有点矫枉过正,我觉得我要么没有正确使用插件,要么应该以另一种方式处理这个问题。也许坚持直接在属性文件中编码特殊字符:
aboutText=Version ${project.version} \u00a9 2012 blabla
?