ANT seems to be corrupting chinese character when

2019-07-15 23:47发布

I have an XSL file which contains the following text:

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

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

<?xml version="1.0" encoding="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)

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>

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

ORDER_NAME=电子客票

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>

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="'çµå­å®¢ç¥'"/>

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.

1条回答
等我变得足够好
2楼-- · 2019-07-16 00:35

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=电子客票

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

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

ORDER_NAME=\u7535\u5B50\u5BA2\u7968

Results in the XSL file containing:

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

As expected.

查看更多
登录 后发表回答