é becomes &195;#169 and then becomes é How do I fix this encoding issue?

I have a java file in Eclipse that is in UTF-8 and has some strings containing accents.

In the java file itself, the accent is written and saved as é . In the xml that is generated using velocity the é becomes é In the pdf that is generated using fop and and an xsl template, the output is displayed as é

So this is probably an encoding issue and everything should be in UTF-8. What's weird is that locally in my eclipse environment (windows) where I run the application, the whole process works and the correct accents é are displayed in the pdf.

However when the application is built with maven and deployed to a (unix environment) I see the problem described above.

Answers


Perhaps Eclipse is compiling the file with a different javac command line than Maven.

When you compile Java, you have to tell the compiler the encoding of the source files (if they contain non-ASCII characters and the default doesn't work).

javac -encoding utf8 MyCode.java

I think the way to fix this in Maven is to add this to your pom.xml file:

<project>
  ...
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  ...
</project>

(I got that from a Maven FAQ about a slightly different issue.)

You could instead avoid the encoding issue entirely by using ugly Unicode escape sequences in your Java file. é would become \u00e9. Worse for humans, easier for the toasters. (As Perlis said, "In man-machine symbiosis, it is man who must adjust: The machines can't.")


Need Your Help

Find First character in string that is a letter C#

c# string char

Hello I am trying to figure out how to look through a string, find the first character that is a letter and then delete from that index point and on.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.