0
votes

I have a very large Java program that needs to default to UTF-8 encoding. When I run it in eclipse, I can just change the default character encoding to UTF-8 in Run Configurations, but the encoding is something else whenever I export the code as a runnable jar rendering the text unreadable. Is there a way to set the default encoding when compiling a jar? My program reads from 20+ files, so it would be inefficient to specify character encoding every time I read or write (although possible if there is no other way). Thank you!

1

1 Answers

1
votes

I'm afraid it's not possible to do at compile time. You'll need to set the file.encoding system property when launching the JVM, or change your code to specify an charset. As painful as it may be, I would recommend the second option; relying on the default charset is seldom a good idea.

See also: Setting the default Java character encoding?