The last week I've been trying to figure out why some stream decoding my newly adopted application is doing was giving me some major encoding problems. Finally I figured out that the problem was that the JARs/WAR being built with Ant and deployed to the server were being compiled with the javac task using the encoding UTF-8 instead of the system default of CP1252.
This seems to be caused mainly by having many hard coded strings/chars for these special characters.
This was easily resolved by either of the following steps:
So why is Ant in Eclipse changing to UTF-8? Is this configurable? Where do I configure it?
System
Ant, run from Eclipse, using all the same versions (except I have Java 1.6.0_15) treats my Java source files as Windows-1252
. My workspace and projects are using the default settings.
UTF-8 to match the byte code on the server
I'm not sure what you mean by this - you mean the encoding of the source files, surely. The bytecode is a structured set of instructions; string literals built into the class files are always UTF-8.
I would use Unicode escape sequences to make my files more encoding-agnostic. You can use tools like native2ascii or the java.nio.charset API to help with this.
When using Ant on the command line, it automatically uses the system default encoding, which seems to be windows-1252 on your system.
When using Ant from Eclipse, it reads the local encoding property of the source files/folders to determine which one must be used. This property is in the Resource page of the Properties dialog, available when right-clicking on a source folder.
When nothing is specified, the workspace wide default encoding is used. It is configurable from withing the Window>Preferences dialog.
Hope this helps.
Something similar is happening on my computer. It's Windows, and the text file encoding configuration in Eclipse is set at the default (Cp1252).
Ant from the command-line does not throw a fit when compiling code with "strange" characters (e.g., í, ñ, ü). But the same Ant task from inside Eclipse does.
I've had to configure the Ant task in Eclipse with this parameter in the JRE tab:
-Dfile.encoding=Cp1252
The javac part of the Ant task works fine now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With