Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #36605

Re: How to compile source files encoding in utf-8 with eclipse?

From Marcel Mueller <news.5.maazl@spamgourmet.org>
Newsgroups comp.lang.java.programmer
Subject Re: How to compile source files encoding in utf-8 with eclipse?
Date 2017-05-12 15:04 +0200
Organization MB-NET.NET for Open-News-Network e.V.
Message-ID <of4btq$479$1@gwaiyur.mb-net.net> (permalink)
References <of44h5$1sgk$1@gioia.aioe.org>

Show all headers | View raw


On 12.05.17 12.58, parmenides wrote:
> javac -encoding utf-8 filename -classpath ...
>
> and copied the generated class file into tomcat's app directory. The
> page display the chniese characters normally. I think the difference is
> at the encoding of class file.

I think there is nothing like 'encoding' in a class file. Java string 
are always UTF-16 aka UCS-2.

But of course, javac need to be able to read your string literals while 
compiling. That's the problem. You need to pass this option to the javac 
compiler too. AFAIK javac uses the systems (or users) default setting. 
But if you override this in eclipse you need to override it for javac too.

> I can change that by command line with
> -encoding option, but how to do that with Eclipse? Or there something I
> have not been aware of.

This is probably a setting of the Java builder in the project settings. 
(I just can't check because I have currently only CDT installed.)

However, you may also set the environment for the entire eclipse IDE by 
setting the environment variable LANG appropriately before the eclipse 
start. But keep in mind that this also applies to the file names in Unix 
like systems. So if your file names or paths contain special characters 
they may no longer display correctly after this change. Windows handles 
file names differently. They are always converted form or to UTF-16.

Another option that might work: precede all you files with a BOM marker 
as first UTF-8 character. Most applications will auto-detect them as 
UTF-8 afterwards. Maybe also javac. Some application hav an extra 
setting for this purpose: "UTF-8 with BOM" or something like that.


Marcel

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

How to compile source files encoding in utf-8 with eclipse? parmenides <xparmenides@yahoo.com> - 2017-05-12 18:58 +0800
  Re: How to compile source files encoding in utf-8 with eclipse? Marcel Mueller <news.5.maazl@spamgourmet.org> - 2017-05-12 15:04 +0200

csiph-web