`
arthurln
  • 浏览: 42465 次
社区版块
存档分类
最新评论

关于Ant的Copy Task

阅读更多
  一个配置文件是xml格式的,里边有中文字段,编码格式为UTF-8,在Unit Test里边跑没有问题,用ant发布到服务器上就出xml解析异常:Invalid byte 3 of 3-byte UTF-8 sequence。打开服务器上的文件,是乱码,根源是ant的Copy Task的问题。在Ant的文档(http://ant.apache.org/manual/CoreTasks/copy.html)中是如此记述的:

Important Encoding Note:  The reason that binary files when filtered get corrupted is that filtering involves reading in the file using a Reader class. This has an encoding specifing how files are encoded. There are a number of different types of encoding - UTF-8, UTF-16, Cp1252, ISO-8859-1, US-ASCII and (lots) others. On Windows the default character encoding is Cp1252, on Unix it is usually UTF-8. For both of these encoding there are illegal byte sequences (more in UTF-8 than for Cp1252).

How the Reader class deals with these illegal sequences is up to the implementation of the character decoder. The current Sun Java implemenation is to map them to legal characters. Previous Sun Java (1.3 and lower) threw a MalformedInputException. IBM Java 1.4 also thows this exception. It is the mapping of the characters that cause the corruption.

On Unix, where the default is normally UTF-8, this is a big problem, as it is easy to edit a file to contain non US Ascii characters from ISO-8859-1, for example the Danish oe character. When this is copied (with filtering) by Ant, the character get converted to a question mark (or some such thing).

There is not much that Ant can do. It cannot figure out which files are binary - a UTF-8 version of Korean will have lots of bytes with the top bit set. It is not informed about illegal character sequences by current Sun Java implementions.

One trick for filtering containing only US-ASCII is to use the ISO-8859-1 encoding. This does not seem to contain illegal character sequences, and the lower 7 bits are US-ASCII. Another trick is to change the LANG environment variable from something like "us.utf8" to "us".

在copy标签上加上encoding="UTF-8",问题解决了。
分享到:
评论

相关推荐

    替换文本文件中Ant表达式的Ant扩展任务

    <taskdef name="copy-with-replace" classpath="${basedir}/release/ant-task-ext.jar;${basedir}/lib/ant-1.9.1.jar;${basedir}/lib/commons-lang-2.6.jar" classname="kingspider.tools.ant.task....

    ant.jar下载

    org.apache.tools.ant.Task org.apache.tools.bzip2.CRC org.apache.tools.ant.Target org.apache.tools.ant.Project org.apache.tools.zip.ZipFile org.apache.tools.zip.ZipLong org.apache.tools.ant....

    Ant 1.9.2 API (CHM格式)

    注:对每一个Ant Task,如Mkdir,Delete、Copy、Move、Zip等,都必须设置一个Project对象,可以几个Ant Task共用一个Project对象,但不能有Ant Task不设置Project对象。 2. 文件拷贝和移动、更名 1)文件copy 1. ...

    ant1.9资源

    接下来开始向读者讲解本节的重点:Ant的关键元素project、target、property和task。 1. project元素 project元素是Ant构件文件的根元素,Ant构件文件至少应该包含一个project元素,否则会发生错误。在每个project...

    ant学习打包代码

    --自定义一个类来處理Task--> <taskdef name="myTaskExample" classname="com.ant.tool.extend.AntTasks" classpath="bin" /> <!--引用自定标签的name myTaskExample--> <!--用echo显示各种的属性--> ...

    LWUIT1.2(20090715)

    exporting ant task, Copy & Paste, complex image borders, improved preview and much more * Support for setUIID in Component allows customizing the component style selector * More options for ...

    jocky 混肴编译rar包(ant和插件俩个版本)

    -- 引入Jocky Ant Task,要确保jocky-ant.jar位于ANT_HOME\lib目录下 --> 3 <taskdef resource="jockytasks"> 4 <target name="build"> 5 <!-- 设置jocky.jar的位置以及混淆级别,当enable为true时,...

    流构建系统GulpJS.zip

    如果你希望写完JavaScript能够一个工具完成代码清理优化工作,Gulp 就是你的不二之选,GulpJS类似Ant或Maven之于Java。 示例代码: var gulp = require('gulp'); var coffee = require('gulp-coffee'); var...

    java 混淆工具,不可逆 jocky 也许是最好的了

    -- 引入Jocky Ant Task,要确保jocky-ant.jar位于ANT_HOME\lib目录下 --> <taskdef resource="jockytasks"> <!-- 设置jocky.jar的位置以及混淆级别,当enable为true时,javac task将被自动替换成Jocky混淆编译器 -...

    joc eclipse plugin

    -- 引入Jocky Ant Task,要确保jocky-ant.jar位于ANT_HOME\\lib目录下 --> <taskdef resource=\"jockytasks\"> <!-- 设置jocky.jar的位置以及混淆级别,当enable为true时,javac task将被自动替换成Jocky混淆...

    Borland Together key

    New (Bug 2261, Trk#30135): Ant task provided for running OCL based Model audits/metrics. Please refer topic Borland Together Modeling Guide > Procedures > Together Quality Assurance > Running Model ...

    fckedit编辑器

    <taskdef classname="org.apache.catalina.ant.ListTask"> <taskdef classname="org.apache.catalina.ant.ReloadTask"> <taskdef classname="org.apache.catalina.ant.UndeployTask"> 运行ant...

Global site tag (gtag.js) - Google Analytics