is there a standard character encoding for war files? - java

If I create a text file on an operating system that uses the Latin encoding code page ISO/IEC 8859-1. Now if I package the text file as a .war file using the Java jar tool, will it be packaged using the same character encoding as it was on the source Operating System? Or, will it be packaged using some standard encoding such as UTF-8?

The character set encoding for JAR/WAR/EAR is UTF-8. Note however, that this only applies to the entry names, not the file contents, e.g. class file data.

WAR file is basically a ZIP archive with .war extension and it has nothing to do with encodings.

Seems like jar takes the bytes from the text file and stores exactly those bytes in the jar/war file without storing any encoding information. This is gleaned from comments on the question as well as the other answers. The answers do not state this clearly, so I am answering my own question. Please correct if I am wrong.

Related

extract contents of .pkg file in java

I have been trying to unpack a .pkg file, which contains two folders and a .json file, into a directory using Java. I have used the apache.commons.compress library in the past, but unable to use it for the .pkg file. Please let me know how i can do this.
Many thanks
Managed to unpack. The .pkg file was actually a .cpio payload file with some header and tail bytes.

Can source code files with different encoding coexist in (the same) Java (project in Eclipse)?

I know Java uses UTF-16 internally and expects .properties files to be in ISO-8859-1 by default.
I'm currently working on a project that was written in Eclipse, whose default encoding on our systems is cp-1252. I'm thinking utf-8 would be a much more sensible option, going forward.
However, given the scale of the project (it's split up into modules and uses libraries from all over the place), I can't just batch-convert all source code files in one go.
Will Java have a problem with some files in a project being in one encoding and some in another? (Clearly, having entire libraries written in encodings that are different from one another doesn't seem to be a problem - probably because they are all UTF-16 once compiled, anyway.)
Would Eclipse be able to handle that (i.e. different encodings per file) correctly?
Yes you can.
You can choose the default encoding to use for the whole Eclipse project:
right click on a project
resource part
Text file encoding zone, check Other and choose UTF-8 (or what you want) in the combo
You can also change the encoding for a particular file:
right click on the file
resource part
Text file encoding zone, check Other and choose UTF-8 (or what you want) in the combo
Preferences are store in the hidden folder .settings in your project. File encoding preferences are store in the .settings/org.eclipse.core.resources.prefs.
Thoses preferences can be commited using your favorite source control and shared with other developpers.

encoding issue in my web application

I am facing an encoding issue in my web application.
I am using properties file (resource bundle) to store language text.
If I check encoding of my properties file using notepad, it's UTF-8 and I see proper arabic character when I open it in notepad.
LOGIN=دخول
When I build my application using JDeveloper, in my properties file under classes folder, arabic characters are converted like this:
LOGIN=\u062f\u062e\u0648\u0644
Also encoding of this file is shown as ANSI in notepad.
Surprisingly, in browser, characters appeared perfectly fine (دخول).
Now when I build my application using ant, I've a copy task which is copying this properties file from src folder to classes folder.
After running build script, if I see encoding of properties file under classes folder, it still is UTF-8 and characters are in arabic only.
However in browser, characters doesn't appear properly.
As far as I know UTF-8 encoding is supposed to cater for all languages but in my case something is wrong somewhere.
I tried following also in copy task:
encoding="UTF-8" outputencoding="UTF-8"
However still no luck.
Anyone know where I am wrong?
Thanks.
Well, the comment and link provided by Edwin did help.
I moved my translations to XML bundles (also called as XLF or XLIFF bundle in ADF) and now everything is working fine.
Thanks.
right click the properties file > prefrences > Environment > Encoding >utf8

Pootle - issues exporting properties files

I am using pootle for localization.
I imported source translations from Java properties files.
the property file looks like:
STR_TEXT1 = Hello
Than I imported other language files. I paid translators to translate those other languages.
Now I need to export those translations from pootle back to JAVA property files. Problem is, that it randomly exports it to UTF8 other time to to \uXXXX escape Encoding. There is no way how to setup the encoding for export files. Second problem is, that those export files are corrupted. It renders them like many rows without problem and some rows are cut, like this:
STR_TEXT1 = HELLSTR_TEXT2 = bye
Than I accidently deleted property files from /po/my_project directory. When I did this, exports stoped to work. But all translations are still wisible on the pootle web. So, i suppose those translations are saved in some other files, maybe mo files. Is there a way how to get those translations to java property files? how to force pootle to replace those original texts from original property files by fresh texts from pootle?
Pootle should export you files as Latin1 not UTF-8, it will escape non-Latin characters using \uXXXX syntax. Newer Pootle's allow you to export in UTF-8.
The best is to attach your source and translated files to a bug over at bugs.locamotion.org so that the Pootle developers can look at your source files.
The translations are kept in a database. Pootle makes use of you template file usually en.properties to create translated versions. I haven't tested what happens if you delete this template file.

I need some help with using a JAR file

Okay I understand this might be a simple question, but I was trying to figure out how to make a JAR file so that other people can run my program without having a software like jGrasp, eclipse, or netbeans. The problem I'm having is I save it as a JAR file and can execute it on my computer but when I email it to my friend, it says invalid or corrupt JAR file. Can anyone explain? Thanks
Are you creating the file with the jar command? Does "jar tvf fn.jar" show you the contents? If so, the problem is probably with the email transfer. Keep in mind that a jar file is actually just a zip file with some special data in it, and some email servers will refuse to pass along zip files because of all the trojans that use emailed zip files.
One common problem would be if your email client isn't mime encoding it, so something along the way changes 0x0D (carriage returns) to 0x0D 0xOA (carriage return + line feed) or vice versa, which corrupts the hell out of binary files.

Categories

Resources