0

I have UTF-8 string literals hardcoded in my java files. Eclipse builds this application correctly, so resulting class files contains those strings in UTF-8. But If use ant build.xml, resulting class files contains strings with incorrect encoding.

I already tried adding encoding="UTF-8" to the javac task, but with no success.

How it can be fixed?

p.s. I know this is quite bad practice to have string literals hardcoded in the source files, but this is situation when I need it there, so please don't suggest to extract it to the resource bundle.

Any help is greatly appreciated

Sergey Karpushin
  • 874
  • 1
  • 10
  • 33

3 Answers3

1

Proper way is

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

If in resulting class files strings are in incorrect encoding, it means that probably your source encoding is not UTF-8, or these files are compiled by some other javac task, not the one you modified.

Mikhail Vladimirov
  • 13,572
  • 1
  • 38
  • 40
  • I did it and did double check that sources is in UTF-8. It didn't help. And I have only one javac task in my ant file, so I don't think this is the reason. – Sergey Karpushin Apr 22 '13 at 05:37
0

The encoding must match the encoding of the file. Your guess of utf-8 may not be correct. Please check other suitable encoding names like iso-8859-1.

Please check upvoted answers in How do I set -Dfile.encoding within ant's build.xml?

Community
  • 1
  • 1
Jayan
  • 18,003
  • 15
  • 89
  • 143
0

This is not actually an answer to original problem, but I don't want this question to be unanswered. Maybe moderators will decide to delete it. Anyway.

Looks like this is some kind of bug when using specific combination of ant, jdk, windows. I dug really deep and wasn't able to fix this in a let's say normal way.

So I decided to externalize string to properties file, which is anyway better practice...

Normally solution suggested by Mikhail Vladimirov should work fine, but not this time.

Sergey Karpushin
  • 874
  • 1
  • 10
  • 33