Loading a Java Charset manually

走远了吗. 提交于 2019-11-28 00:10:18

There's a bit more to using a new Charset, apart from putting the necessary classes into the classpath. To quote the Javadocs:

A charset provider identifies itself with a provider-configuration file named java.nio.charset.spi.CharsetProvider in the resource directory META-INF/services. The file should contain a list of fully-qualified concrete charset-provider class names, one per line. [...]

( http://download.oracle.com/javase/6/docs/api/java/nio/charset/spi/CharsetProvider.html )

Is this special file present in the JAR?

You should make sure the jar is loaded by the main classloader. You can achieve this by adding the jar to the JVM's jre/lib/ext extension directory, or by adding it to the classpath of the main program. For example if you are using Tomcat, add -cp /path/to/jutf7.jar to Tomcat's startup script.

Similarly, if you want to test jutf7 from the scala REPL, you need to start it as follows

env JAVA_OPTS="-cp /path/to/jutf7-1.0.0.jar" scala

Tested with Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!