1

I created a jar using the Export functionality in Eclipse and when I try to execute it in the following way it fails

java -jar Code.jar

However it works correctly for

java -Dfile.encoding=UTF-8 -jar Code.jar

Current manifest file

Manifest-Version: 1.0
Main-Class: test.Reader
Class-Path: .

How can I mention the encoding inside the manifest file? So that I dont have to mention it explicitly while running the jar file?

Abi
  • 1,335
  • 2
  • 15
  • 28
  • MANIFEST.MF is always UTF8 (https://docs.oracle.com/en/java/javase/18/docs/specs/jar/jar.html#name-value-pairs-and-sections) – Grim Sep 13 '22 at 09:50

1 Answers1

1

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.

and, no, you can't specify that in the manifest.

jtahlborn
  • 52,909
  • 5
  • 76
  • 118
  • you are right, i had not mentioned the default charset while creating my output streams and now it is working, thanks! – Abi Feb 14 '13 at 05:47