激活资源过滤后编码错误

Ral*_*lph 8 encoding character-encoding maven-3 maven

我正在开发一个基于maven的web项目.在我的网络模块中,我使用不同语言的特定资源包(德语,西班牙语......).我所有的资源都是基于UTF-8而且一切正常.现在有必要根据不同的maven配置文件来激活maven资源过滤来替换一些配置.

我的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">
.....

 <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 </properties>    
 <build>
 <resources>
    <resource>
    <directory>src/main/resources</directory>
        <filtering>true</filtering>             
    </resource>      
 </resources>
 ....
Run Code Online (Sandbox Code Playgroud)

从那时起,我的war文件包含编码错误的资源包.例如,德语变音符号不再正确显示在我的Web应用程序中.当我禁用资源过滤时,一切都很好.

我找到的唯一解决方案是将属性project.build.sourceEncoding设置为'ISO-8859-1'

<properties>
  <project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
</properties>
Run Code Online (Sandbox Code Playgroud)

但我不明白为什么这是必要的?我的所有来源都是UTF-8,我的应用程序也是基于UTF-8?如果我需要添加资源包 - 例如日文字符会发生什么?

我正在使用Eclipse 4.2和Maven 3在Linux上进行开发

gre*_*ker 4

您可以在资源插件配置中指定编码,如下所示:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          ...
          <encoding>UTF-8</encoding>
          ...
        </configuration>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>
Run Code Online (Sandbox Code Playgroud)

链接到文档

  • 我之前测试过这个,但没有效果。 (2认同)