开发者

how to encode in Ant

I have a test script:

   <?xml version="1.0" encoding="UTF-8"?>
   <project name="test" basedir=".">
   <echo encoding="UTF-8" file="test.txt">测试</echo>
   </project>

When I open test.txt. I only see "??"

Something more weird. The script run with no problem using Eclipse Ant tool, but it has problem with command line.

Both Eclipse and cmd are using the same开发者_开发百科 Ant lib.


Use this encoding :

 <echo encoding="UnicodeLittleUnmarked" file="test.txt">测试</echo>

And you will get the correct result in your file.


I found the reason.

Before running the Ant script, I need to set a system property:

Set ANT_OPTS=-D"file.encoding=UTF-8"

Then

<project name="test" basedir=".">
   <echo file="test.txt">测试</echo>
</project>

runs successfully even if there is no encoding in the echo.

Can anyone tells me why the original one doesn't work?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜