I have a GUI application with menu, items, labels and so on. Their visible name contains unicode characters. Now, i need to display this application properly, with unicode characters. If i run jar, java uses default system encoding, which is not unicode. I can fix this problem by adding an argument -Dfile.encoding=UTF-8 to a command line with a -jar <app.jar>
. But let's say i want to give jar to someone, and it may be dumb for him to open CMD and pass some arguments to java. Actualy, java vm is a program where startup arguments do big things. Java applications are running in java vm. Since manifest.mf passes to jvm argument about path to main method of a program that it is going to be executed, why we don't have for example function in manifest.mf file, an array of args that will be used in jvm when running app. I know that java is more used to make utility things and for GUI apps there is C, but java is a great language, except some disadvantages of virtual machine. I had an idea of my main program that it will open new java vm with appropriate arguments and run the app there. Then, kill itself. I also know about wrapping jar to exe so the exe file will run jvm and app, but then i loose multi-platform compactibility. Thanks for answers. Hopefully i didn't wrote here somethink useless.

- 331
- 1
- 9
-
“for GUI apps there is C”—big LOL. But seriously, you should read the name of the property `file.encoding` and read it again and again, thinking about what it is trying to tell you. After your have read the name slowly multiple times, does it still surprise you, when I tell you now that it has *nothing* to do with a GUI? – Holger Oct 19 '15 at 14:39
-
Yeah, i get it. I just want to say, by writing app in C, i would have full control over my program and virtual machine would not limit me. And i think if i had CLI application, i should define my custom stream and encoding. But how to do it with GUI where i use some libraries. – Patrik Staron Oct 19 '15 at 19:47
-
It seems you still don’t get the point. There is no reason to kludge with this property; it is entirely irrelevant to GUI applications. The GUI libraries use unicode. The only place where this is relevant is (file) I/O *if you don’t specify an encoding* in your code. There is no function that forces you to use the system’s default encoding, for every function that deals with that default encoding, there is an alternative that accepts an encoding as parameter. If your application doesn’t want to use the default encoding, it does’t have to. Your problem is *not* that you have a GUI. – Holger Oct 20 '15 at 08:51
1 Answers
Several questions here, but let me give you a general guidance:
When you pack a JAR, the metadata in the JAR file, such as the entry names, comments, and contents of the manifest, must be encoded in UTF8 (holds same for the labels etc...). This holds true no matter if you pack JAR by using command line utilities or some IDE. So first of all check that your files with labels etc. are UTF8-encoded.
It might be possible that your own OS has non-unicode setup. So when you edit and save .properties (or whatever) file with labels, they are actually not saved in UTF8.
If you pack "launchable" JAR it should work out with UTF-8 as long as you have UTF-8 labels inside JAR.
Take look at this question also: How to Force a jar to uses(or the jvm runs in) utf-8 instead of the system's default encoding
-
1Property files are stored using `ISO Latin-1` aka `ISO 8859-1`, see [`Properties.load`](http://docs.oracle.com/javase/8/docs/api/java/util/Properties.html#load-java.io.InputStream-)… – Holger Oct 19 '15 at 14:43