激活资源过滤后的编码错误 [英] Wrong encoding after activating resource filtering
问题描述
我所有的来源都是以UTF-8为基础,而且这些都可以正常工作。
现在有必要使用maven资源过滤来替换一些配置,具体取决于不同的maven配置文件。
我的pom.xml:
.....
< project xmlns =http://maven.apache.org/POM/4.0.0xmlns: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>
....
从这一刻起,我的war文件包含编码错误的资源包。例如德语变音符不再显示在我的Web应用程序中。
当我禁用资源过滤时,一切都很好。
我发现唯一的解决方案是将property.build.sourceEncoding属性设置为'ISO-8859 -1'
<属性>
< project.build.sourceEncoding> ISO-8859-1< /project.build.sourceEncoding>
< / properties>
但我不明白为什么这是必要的?我所有的来源都是UTF-8,我的应用程序是基于UTF-8的?
如果我需要添加一个资源包(例如日文字符)会发生什么?
我正在使用Eclipse 4.2和Maven 3开发linux, p>
确定您的资源包(.properties)正在使用 UTF-8
?
java.util.Properties
假定 ISO-8859-1
用于资源束编码,请参见 http://docs.oracle.com/javase/6/docs/api/java/util/Properties.html#load(java.io.Reader),我认为Eclipse(as以及IntelliJ IDEA)为这些文件(.properties)授予这种默认编码。
所以,使用文本编辑器检查项目源代码树中这些文件的当前编码,在Windows 记事本2 中可以帮助您
然后配置 maven-resources-plugin
如下所示在maven中配置不同文件类型的编码?
I am developing a maven based web project. In my web module I am using different language specific resource bundles (german, spain, ....). All my sources are based on UTF-8 and erverything works fine. Now it was necessary to acitvate maven resouce filtering to replace some configurations depending on different maven profiles.
my 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>
....
From this moment my war file contains resource bundles with wrong encoding. For example German umlauts are no longer displayed in my web application correctly. When I disable the resource filtering everything is well again.
The only solution I found was to set the property project.build.sourceEncoding to 'ISO-8859-1'
<properties>
<project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
</properties>
But I can not understand why this is necessary? All my sources are UTF-8 and also my application is based on UTF-8? What will happen if I need to add a resource bundle with - for example Japanese characters?
I am developing on linux using Eclipse 4.2 and Maven 3
Are you sure your resource bundles (.properties) are using UTF-8
?
java.util.Properties
assumes ISO-8859-1
for resource bundles encoding, see http://docs.oracle.com/javase/6/docs/api/java/util/Properties.html#load(java.io.Reader), and I think Eclipse (as well as IntelliJ IDEA) honors this default encoding for these files (.properties).
So go and check with a text editor the current encoding for these files in your project source tree, in Windows Notepad 2 can help you with this.
And then configure maven-resources-plugin
like indicated here Configure encoding for different filetypes in maven?
这篇关于激活资源过滤后的编码错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!