0

My Rest-Application delivers data in correct encoding when running under Eclipse. But when I start the application as executable jar on a Windows System, my special characters are broken.

What am I missing?

enter image description here

Michael Hegner
  • 5,555
  • 9
  • 38
  • 64

1 Answers1

1

Eclipse

Eclipse's encoding is set in preferences->general->workspace, which whould by default be inherited from the OS (cp1250 on windows). When you create a "Run as" task, it also stores it. So if you update eclipse's setting, make sure you re-create your "run as" task. You can see the actual value used when launching your application: Run configurations... -> Your Run task -> Common tab.

You can also force an encoding in eclipse.ini by adding -Dfile.encoding=AnotherEncoding at the end.

Command line

When launching from the command line, it takes the system default value, which would be cp1250 on whidows.

You could print the encoding at the very first line of your program, just to see: System.out.println(System.getProperty("file.encoding"));

To specify an encoding from the command line: java -Dfile.encoding=UTF-8 yourApp.jar

See also

Take a look at this too: https://stackoverflow.com/a/14867904/641627

This indicates a problem with your code. Your code is currently depending on the default platform encoding, and doesn't work if that encoding is not "UTF-8". therefore, you should change the places in your code which depend on the default platform encoding to use the "UTF-8" encoding explicitly.

Community
  • 1
  • 1
alexbt
  • 16,415
  • 6
  • 78
  • 87
  • Works awesome, I wonder there is no attribute for the application.properites for solving it? I tried already `spring.http.encoding.charset=UTF-8` and `server.tomcat.uri-encoding=UTF-8` without result – Michael Hegner Oct 17 '16 at 17:08
  • If you debug your application, is the data OK before being displayed on the web page ? Is the data OK when read from the database ? – alexbt Oct 18 '16 at 09:45