处理特殊字符时javac 1.6和javac 1.7之间的不同行为 [英] Different behaviour between javac 1.6 and javac 1.7 when handling special characters

查看:103
本文介绍了处理特殊字符时javac 1.6和javac 1.7之间的不同行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我要感谢你,并明确表示,我在这个问题上一直抨击我的头,好几天,在其他类似的线程中寻找一个解决方案,没有成功。



我们的应用程序负责生成java类,其中一些可能在类名(包括文件名)中包含特殊字符,例如ZoneRéservée435.java强制编码为UTF-8。 >

直到Java 1.6蚂蚁任务:

 < javac source =1.5 target =1.5srcdir =$ {src.dir}destdir =$ {classes.dir}deprecation =ondebug =onclasspathref =classpathfork =falsememoryMaximumSize =512m encoding =UTF-8> 

工作正常。



java 1.7 fileName没有使用UTF-8编码得到保存,导致文件名类似于:ZoneRe?serve?e435.java



环顾四周,我来了解我需要将env变量LC_CTYPE设置为UTF-8。
解决了fileName问题,但是我仍然收到编译错误

 错误:classZoneRéservée435是public的,应该被声明在一个名为ZoneRéservée435.java的文件

虽然它们有相同的名称,但它们似乎被编码在两个不同的方式。
有趣的部分是编码的差异发生在java 1.6中,但编译正常。



有没有人有任何建议或想法?

对于我来了解编码问题是与以下事实相关的事实:

  Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),Charset.forName(UTF-8))); 




  • 文件内的代码正在使用U + 00E9来定义特殊char;

  • 文件名使用eU + 0301;



有关如何处理的任何建议这样吗?

解决方案

似乎您的文件系统使用分解形式的字母é(这是字符 e ' \\而您的代码生成器则使用é的组合表单,\\ u0065 \\\́ (这是 \\\é )。这是Apple的HFS +文件系统的一个典型问题,它总是使用分解的形式。



您可以做什么来解决这个问题是修改应用程序以分解类名在生成的源文件中出现 java.text.Normalizer



归一化器。规范化(classname,Normalizer.Form.NFD)



另见: http://en.wikipedia.org/wiki/Unicode_equivalence


first of all I would like to thank you and to explicitly say that I've been slamming my head on this issue for several days and looking for a solution in other similar threads with no success.

Our application is responsible of generating java classes and some of them may contain special characters in the class name (thus file name) such as ZoneRéservée435.java forcing the encoding to be UTF-8.

Till Java 1.6 the ant task:

<javac source="1.5" target="1.5" srcdir="${src.dir}" destdir="${classes.dir}" deprecation="on" debug="on" classpathref="classpath" fork="false" memoryMaximumSize="512m" encoding="UTF-8">

worked fine.

When moved to java 1.7 the fileName was not getting saved using the UTF-8 encoding resulting in a file name similar to: ZoneRe?serve?e435.java

Looking around I came to understand that I needed to set the env variable LC_CTYPE to UTF-8. That solved the fileName issue but I still get a compilation error

error: class ZoneRéservée435 is public, should be declared in a file named ZoneRéservée435.java

Although they have the same name, they seem to be encoded in two different ways. The interesting part is that this difference of encoding was happening with java 1.6 but was compiling fine.

Does anyone have any suggestion or ideas?

For what I came to understand the encoding issue is related to the fact that the class is generated with the following:

 Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8")));

  • The code inside the file is using U+00E9 to define the special char;
  • The file name uses eU+0301;

Any suggestion on how to deal with this?

解决方案

It seems that your file system uses the decomposed form of the letter é (which is the sequence of the characters e and ´ or \u0065 and \u0301) while your code generator uses the composed form of é (which is \u00e9). This is a typical problem on Apple's HFS+ file system, which always uses the decomposed form.

What you can do to solve this problem is modify your application to decompose the class name that appears in the generated source file with java.text.Normalizer:

Normalizer.normalize(classname, Normalizer.Form.NFD)

See also: http://en.wikipedia.org/wiki/Unicode_equivalence

这篇关于处理特殊字符时javac 1.6和javac 1.7之间的不同行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆