Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

java - Ant encoding problem on Windows - UTF-8 files but spits garbage on diacritics

Somehow I can't get my UTF-8 sources to play nice with Ant.

I get a whole lot of "warning: unmappable character for encoding ascii". I'm going crazy, really. Hours and hours and hours. Btw, I noticed 5 people already used the tag crazy. :-)

And yes, I've read this, this and others. Google also (the first 5 page results of at least 3 or 4 different searches, at least). There are javac options. I've tried. There is also some preset or something (sorry, 3 AM). Didn't work either.

I'm generating Android apk files with Ant. I can't use Eclipse, so no. And by the way, the ant documentation is gibberish to me. Those examples are of no use at all. I've lost count on how much I've tried.

I've tried using the Dfile.encoding option, tried mixing that with CHCP 65001 Windows command. Did all the combinations, and it even makes Ant (Javac I guess) stop spitting errors, but it still doesn't matter. My code still ends up with garbage carachters (a bunch of ?? instead of á, í etc).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Are you specifying the file encoding to the compiler correctly? The java compiler will otherwise default to use the platform's default encoding, which on Windows (for example) is not UTF-8. The encoding is specified by using the -encoding flag to javac.

javac -encoding utf8 ...

And in ant build.xml:

<javac ... encoding="UTF-8" ... />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...