Whenever I start our Apache Felix (OSGi) based application under SUN Java ( build 1.6.0_10-rc2-b32 and other 1.6.x builds) I see the following message output on the console (usually under Ubuntu 8.4):
每当我在SUN Java(构建1.6.0_10-rc2-b32和其他1.6.x版本)下启动基于Apache Felix(OSGi)的应用程序时,我在控制台上看到以下消息输出(通常在Ubuntu 8.4下):
Warning: The encoding 'UTF-8' is not supported by the Java runtime.
警告:Java运行时不支持编码'UTF-8'。
I've seen this message display occasionally when running both Tomcat and Resin as well. If java supports unicode and UTF-8, what causes this message? I've yet to find any reference, or answer to this anywhere else.
在运行Tomcat和Resin时,我偶尔也会看到此消息显示。如果java支持unicode和UTF-8,导致此消息的原因是什么?我还没有找到任何参考,或者在其他地方找到答案。
6 个解决方案
#1
11
According the documentation "Every implementation of the Java platform is required to support the following standard charsets... US-ASCII, ISO-8859-1, UTF-8, UTF-16BE, UTF-16LE, UTF-16." So I doubt that Sun have released a build without UTF-8 support.
根据文档“Java平台的每个实现都需要支持以下标准字符集... US-ASCII,ISO-8859-1,UTF-8,UTF-16BE,UTF-16LE,UTF-16。”所以我怀疑Sun发布了没有UTF-8支持的版本。
The actual error message appears to be from here, which is part of the Xerces XML parser. I imagine it is the XML parser where the problem is occurring.
实际的错误消息似乎来自此处,它是Xerces XML解析器的一部分。我想这是问题发生的XML解析器。
#2
7
Try the following program:
尝试以下程序:
import java.nio.charset.Charset;
public class TestCharset {
public static void main(String[] args) {
System.out.println(Charset.forName("UTF-8"));
}
}
If this throws an exception, then there is something wrong with your JDK. If it prints "UTF-8" then your JDK is OK, and your application is doing something odd.
如果这会引发异常,那么JDK就会出现问题。如果它打印“UTF-8”,那么你的JDK就可以了,你的应用程序正在做一些奇怪的事情。
If that's the case, run your app under the debugger, and put a breakpoint in http://www.java2s.com/Open-Source/Java-Document/XML/xalan/org/apache/xml/serializer/ToStream.java.htm --that's the place this warning is produced, and step to see why Xalan can't find the encoding.
如果是这种情况,请在调试器下运行您的应用程序,并在http://www.java2s.com/Open-Source/Java-Document/XML/xalan/org/apache/xml/serializer/ToStream.java中添加断点。 .htm - 这就是产生这个警告的地方,并看看为什么Xalan无法找到编码。
#3
2
Most probably someone put a catch() expecting to have only unsupported encoding exceptions, so he used the appropriate message. But he has used too wide exception specification (e.g. catch( Exception ex ) ), so when at runtime he's got something else (non-valid XML, NPE, ... ) the message became misleading.
很可能有人把catch()期望只有不受支持的编码异常,所以他使用了相应的消息。但是他使用了太宽泛的异常规范(例如catch(Exception ex)),因此在运行时他还有其他东西(无效的XML,NPE,......),这些消息会产生误导。
#4
0
Try a different (stable release) JVM. I had this problem once and it turned out that the machine was running a beta version JVM that indeed did not support UTF-8, contrary to the requirement in the API docs.
尝试使用其他(稳定版本)JVM。我曾经遇到过这个问题,事实证明该机器运行的测试版JVM确实不支持UTF-8,这与API文档中的要求相反。
#5
0
It should be "UTF8", without the dash.
它应该是“UTF8”,没有破折号。
#6
0
If you are getting this message when using a Transformer, try to specify the TransformerFactory:
如果您在使用Transformer时收到此消息,请尝试指定TransformerFactory:
链接
#1
11
According the documentation "Every implementation of the Java platform is required to support the following standard charsets... US-ASCII, ISO-8859-1, UTF-8, UTF-16BE, UTF-16LE, UTF-16." So I doubt that Sun have released a build without UTF-8 support.
根据文档“Java平台的每个实现都需要支持以下标准字符集... US-ASCII,ISO-8859-1,UTF-8,UTF-16BE,UTF-16LE,UTF-16。”所以我怀疑Sun发布了没有UTF-8支持的版本。
The actual error message appears to be from here, which is part of the Xerces XML parser. I imagine it is the XML parser where the problem is occurring.
实际的错误消息似乎来自此处,它是Xerces XML解析器的一部分。我想这是问题发生的XML解析器。
#2
7
Try the following program:
尝试以下程序:
import java.nio.charset.Charset;
public class TestCharset {
public static void main(String[] args) {
System.out.println(Charset.forName("UTF-8"));
}
}
If this throws an exception, then there is something wrong with your JDK. If it prints "UTF-8" then your JDK is OK, and your application is doing something odd.
如果这会引发异常,那么JDK就会出现问题。如果它打印“UTF-8”,那么你的JDK就可以了,你的应用程序正在做一些奇怪的事情。
If that's the case, run your app under the debugger, and put a breakpoint in http://www.java2s.com/Open-Source/Java-Document/XML/xalan/org/apache/xml/serializer/ToStream.java.htm --that's the place this warning is produced, and step to see why Xalan can't find the encoding.
如果是这种情况,请在调试器下运行您的应用程序,并在http://www.java2s.com/Open-Source/Java-Document/XML/xalan/org/apache/xml/serializer/ToStream.java中添加断点。 .htm - 这就是产生这个警告的地方,并看看为什么Xalan无法找到编码。
#3
2
Most probably someone put a catch() expecting to have only unsupported encoding exceptions, so he used the appropriate message. But he has used too wide exception specification (e.g. catch( Exception ex ) ), so when at runtime he's got something else (non-valid XML, NPE, ... ) the message became misleading.
很可能有人把catch()期望只有不受支持的编码异常,所以他使用了相应的消息。但是他使用了太宽泛的异常规范(例如catch(Exception ex)),因此在运行时他还有其他东西(无效的XML,NPE,......),这些消息会产生误导。
#4
0
Try a different (stable release) JVM. I had this problem once and it turned out that the machine was running a beta version JVM that indeed did not support UTF-8, contrary to the requirement in the API docs.
尝试使用其他(稳定版本)JVM。我曾经遇到过这个问题,事实证明该机器运行的测试版JVM确实不支持UTF-8,这与API文档中的要求相反。
#5
0
It should be "UTF8", without the dash.
它应该是“UTF8”,没有破折号。
#6
0
If you are getting this message when using a Transformer, try to specify the TransformerFactory:
如果您在使用Transformer时收到此消息,请尝试指定TransformerFactory:
链接