Tomcat restart or redeploy breaks unicode characters from java source files - java

I have developed a liferay 6.2 application using jsf and primefaces 4. I have unicode characters both in xhtml files and java source files. There a strange behaviour of breaking my characters after tomcat restart or redeploy of application and the problem is only with characters coming from the source files. The rest unicode characters on the page are displayed correctly. And the behaviour is not always reproducible.
I have read posts referring to setting the jvm's or tomcat default encoding and main suggested action was setting -Dfile.encoding=UTF-8 but didn't have any luck.
I am using tomcat 7.0.42

If you are using Eclipse, try setting the text encoding in your project Properties>Resource

The problem has to do with the encoding of the class files. The solution was to set the correct encoding for javac. I finally discovered that in eclipse I had to edit the build.user.properties file to set javac.encoding = UTF-8

Related

How to change a default charset for Java machine in Eclipse?

I am finding any elegant method, how can I change default charset of Java machine to UTF-8 in Eclipse. I have found many methods, how to do from source code, but I would like to know, how to do it fast, easy, from Eclipse IDE without writing java source code.
Thanks.
You can change the workspace default encoding for all files in the Preference page Workspace, about the bottom left of the dialog. All new projects and files will have that encoding.
However, if you are using existing projects, be vary of three things:
Existing files saved with a different encoding might need conversion; it will not happen automatically.
Projects (or files or folders in projects) might have alternative default encodings (set Resource page of the Properties dialog). Those settings are more specific, and will not be affected by the generic workspace settings. Furthermore, these settings are shared with the project, e.g. through version control, so if you collaborate with others, make sure to set up encoding together.
This is not Java specific; there is no supported way to do it only for Java projects.
Edit: as you want to edit the default character encoding for your application, see the answer Setting the default Java character encoding?
In short, you have to set it up as a JVM parameter, like
java -Dfile.encoding=UTF-8 … com.x.Main

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

PostgreSQL encoding issue

I am running a local postgresql server in version 9.1 and using the postgresql-9.1-901.jdbc4.jar for my java application to access the database.
Though i set the encoding to UTF8 and restarted the server, it is not possible to insert (using the application) values with german umlauts like äöü. The result looks like this: √§√∂√º√ü
I already checked everywhere the encoding and even downgraded the server to version 9.0 with corresponding driver, but nothing helped.
Thanks for helping!
mmm...
Make sure the text you send to db is also UTF-8 encoded. This means:
if you have it in a .properties file or something similar make sure that file is UTF-8 encoded (just open it in notepad++ and look what encoding it reports)
make sure you're compiling your Java code in UTF-8:
in in Eclipse, right-click project -> properties -> Resource -> Text File Encoding should be UTF-8
if building with Maven, make sure your pom.xml contains:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
if plain-ole command line compiling, do a :
javac -encoding UTF-8 *.java
I found the solution for this problem. I was working with Mac OSX Lion, and the default system encoding changed to MacRoman after updating. However, changing the encoding fixed my problem.

Ear encoding inside the archive

These days, I drove crazy to deploy an ear on unix enviroment using Weblogic.
At the end I realized by using (cat -v file.properties) that such file was full of ^M at the end of the line.
This happened because I edited the properties file on Windows and I transfered to the production eviromnment by FileZilla.
By the usage of dos2unix command, I addressed the problem and the encoding of the file right now is correct.Because the properties file it's not the only one I edit, but I open the ear archive and customize the config.xml too, and then close the ear again and transfer it to linux, do you think that the encoding of that xml can be a problem even if it's embedded inside the ear ?
Thanks
You could remove the carriage return characters automatically with ants fixcrlf.
If you use maven you could also run an ant task to prepare the files.

Strange file name character encoding problem with Ubuntu / Java / Glassfish

I have a Java application deployed on Glassfish web server on Ubuntu Server Edition PC.
One of the services this application has to provide is to mount an ISO image in a specific folder and copy all the contents of this folder to another destination.
Since once my Java method found a Cyrillic file name, it has crashed. This file name appears as "???????????????.txt" in server application logs.
First I thought this was a linux problem, because this file appeared incorrectly in terminal as well. After I added CP1251 locale the problem in linux terminal has solved but still my application was throwing an error.
One guy at UbuntuForums (http://ubuntuforums.org/showthread.php?t=1813920) suggested me to convert this bad file with "convmv" utility, but this utility's output said that this file was already a UTF-8.
After that I've created a test application with the same methods and run it on the same PC but just like "java Test $arguments$".
And it did worked!
Simple System.out.println method displayed the file name correctly and successfully copied the problem file to another folder.
This fact left me no choice but to claim Glassfish for being the gap between my class, java and linux (though I'm not sure how it's possible).
Is there any character encoding specific settings in Glassfish I could correct to fix this error or maybe I'm missing something and the problem isn't really there?
Thanks in advance!
Andrew
Try to change Charset.defaultCharset(). See Setting the default Java character encoding? for more details.
Also, see Glassfish configuration such as
In sun-web.xml You have to see something like this:
<locale-charset-info default-locale="">
<parameter-encoding default-charset="UTF-8"/>
</locale-charset-info>

Categories

Resources