ANT 在部署项目时似乎会损坏汉字 [英] ANT seems to be corrupting chinese character when deploying project

查看:29
本文介绍了ANT 在部署项目时似乎会损坏汉字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含以下文本的 XSL 文件:

I have an XSL file which contains the following text:

<xsl:variable name="orderName" select="'@ORDER_NAME@'"/>

在 XSL 文件的顶部,编码设置为 UTF-8

At the top of the XSL file the encoding is set to UTF-8

<?xml version="1.0" encoding="UTF-8"?>

如果我在 Eclipse 中检查文件属性,则文本文件编码被列为:默认(由内容类型决定:UTF-8)

And if I check the file properties in Eclipse, the Text file encoding is listed as: Default (determined from content type: UTF-8)

然后是一个ANT过滤设置文件:

There is then an ANT filter set file:

<project name="filterset" basedir=".">
    <property name="conn" value="TEST"/>
    <filterset id="conn_props">
        <filter token="ORDER_NAME" value="${ORDER_NAME}"/>
    </filterset>
</project>

然后在 .properties 文件中定义 ORDER_NAME 的值

The value of ORDER_NAME is then defined in a .properties file

ORDER_NAME=电子客票

这是为部署而运行的 ANT deploy.xml 的摘录

Here's an excerpt from the ANT deploy.xml which is run for deployment

<copy todir="${working.dir}/config" failonerror="false" overwrite="true" encoding="UTF-8">
    <fileset dir="${supplier.dir}">
        <include name="Supplier/**/*.xsl"/>
        <include name="Supplier/**/*.xml"/>
    </fileset>
    <filterset refid="conn_props"/>
</copy>

这应该将 XSL 文件从 Supplier 目录复制到 config 目录并替换 ORDER_NAME 标记.但是在部署项目并打开文件后,文本被损坏为:

This should copy the XSL file from the Supplier directory to the config directory and replacing the ORDER_NAME token. However after deploying the project and opening the file the text is corrupted to:

<xsl:variable name="orderName" select="'çµå­å®¢ç¥'"/>

我在 Windows 7 64 位、Eclipse Juno 32 位和 ANT 1.7.1 上运行它(Ant 版本不能升级).我见过类似的问题,但没有任何令人满意的答案(或任何似乎适用于这种特定情况的问题).谢谢.

I'm running this on Windows 7 64-bit, on Eclipse Juno 32 bit with ANT 1.7.1 (Ant version cannot be upgraded). I have seen similar questions, but not any with satisfactory answers (or any that seem to apply to this particular scenario). Thanks.

推荐答案

我自己解决了这个问题,但有可能其他人无法复制我的问题,因为我为了简化而从我的原始问题中遗漏了信息(我为清楚起见,已经对问题进行了编辑).

I solved this myself, but it is possible others were not able to duplicate my issue as a result of me leaving information out of my original question for simplification (I've since edited the question for clarity).

问题是属性文件的文件类型包含:

The problem was the file type of the properties file containing:

ORDER_NAME=电子客票

UTF-8 并且它需要是 ISO-8859-1,因为这是 ANT 所期望的,请参阅:Apache Ant 属性

was UTF-8 and it needs to be ISO-8859-1, as this is what is expected by ANT, see: Apache Ant Property

因此将文件转换为 ISO-8859-1 并重新定义 ORDER_NAME:

So converting the file to be ISO-8859-1 and redefining ORDER_NAME:

ORDER_NAME=\u7535\u5B50\u5BA2\u7968

生成包含以下内容的 XSL 文件:

Results in the XSL file containing:

<xsl:variable name="orderName" select="'电子客票'"/>

正如预期的那样.

这篇关于ANT 在部署项目时似乎会损坏汉字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆