0

I have a problem with the accent character in different platforms.

When I log this in my machine under fedora (where default charset is UTF-8) it is printing correvtly as Sacré Coeur.

But when i update to another server that is running on RedHat (where default charset is ISO-8859-1), it is printing as Sacré Coeur.

I want to log it in RedHat server as same as in my my Fedora machine. How can I do this?

My Workout :

  • I tried to changes the System.setProperty("file.encoding", "ISO-8859-1"); in local with the purpouse of doing the reverse version System.setProperty("file.encoding", "UTF-8"); in the RedHat Server, if it change the way of logging in the local. But nothing changed.
  • I noticed there are couple of threads regarding the accent character but nithing answers me. That's why I asked a new question.
  • I tried this one as well but not working.

    System.setProperty("file.encoding","ISO-8859-1"); Field charset =Charset.class.getDeclaredField("defaultCharset"); charset.setAccessible(true); charset.set(null,null);

  • But I didn't try to set the charset at the JVM start. If it will works please explain me how can I do it?
Community
  • 1
  • 1
ironwood
  • 8,936
  • 15
  • 65
  • 114
  • What library are you using to log the information? Is it plain `System.out.println()`? – asgs Mar 06 '13 at 00:35
  • 2
    When you say "it is printing", what environment are you talking about? Desktop? Pages served by a web server? Swing? – T.J. Crowder Mar 06 '13 at 00:35
  • @ asgs, @ T.J. Crowder : For quicke testing I used sysouts. but in the serever I'm using org.apache.Logger. In both there are not working. And I log the results as XML files. I want to change the XML logging as well – ironwood Mar 06 '13 at 00:41
  • Have you read http://stackoverflow.com/questions/361975/setting-the-default-java-character-encoding? – Perception Mar 06 '13 at 00:45
  • @Perception :yep I have referenced it in my question(I tried this one as well but not working.) this one refers to the link. But I didn't try to set the charset at the JVM start. If it will works please explain me how can I do it? – ironwood Mar 06 '13 at 00:57
  • 2
    @NamalFernando - you can specify additional properties for the JVM via the -D argument. Eg: `java -Dfile.encoding=UTF-8 MyClass` – Perception Mar 06 '13 at 01:01
  • @Perception : Thanx. I tried it with eclipse vm argument setting. It works as you mentioned.+1ed :). I'm building my jar files using ANT. and server is jetty. How to set these arguments relevant to them? – ironwood Mar 06 '13 at 01:29
  • @NamalFernando - code wont fit in comments, but you can read about how to set Java system properties for Ant [here](http://ideoplex.com/id/372/setting-java-system-properties-with-ant). – Perception Mar 06 '13 at 01:36

1 Answers1

1

To get similar out put from all the environments, with out depending on the server OS default character encoding, when you start your program or the server environment (Jboss tomcat or jetty) pass -Dfile.encoding to the start-up script

(lets say run.sh in jboss, add -Dfile.encoding=UTF-8 to JAVA_OPTS)

-Dfile.encoding=UTF-8

Supun Sameera
  • 2,683
  • 3
  • 17
  • 14