Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 227
Andrew Avatar asked Aug 22 '11 18:08

Andrew


1 Answers

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>
like image 180
alexsmail Avatar answered Oct 05 '22 23:10

alexsmail