DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

中文Windows上安装Jython字符串处理异常的解决办法


The Jython console didn't work properly on my Chinese version Windows XP. It can not interprete the strings properly.

e.g.

print "hello world"

....

Looks like it's looking for a futher input. After I input a '\n', ther console crashed and complains

LookupError: unknown encoding 'gb18030'.

This error never happens on the English version Windows XP. So, this problem definitely caused by the system default encoding.

With a few hours study for the JVM & the Jython encoding setting, I found 2 solutions.

1) Change the JVM default character encoding

Start up the jython with option -Dfile.encoding=UTF8,then the Jython console's encoding will be UTF8 as well.

e.g.

jython -Dfile.encoding=UTF8

For change the JVM encoding automatically, you can also create one environment variable JAVA_TOOL_OPTIONS to -Dfile.encoding=UTF8.

e.g.

set JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF8"

2) Change the Jython console character encoding

Start up the jython with option -Dpython.console.encoding=UTF8

e.g.

jython -Dpython.console.encoding=UTF8

Or add this setting in the Jython registry file. On my laptop, the file is C:\jython25\registry

Now, you enjoy.


2013-03-19更新

命令行输出

java -jar -Dpython.console.encoding=UTF-8 jython-2.5.3.jar

执行文件

java -jar -Dfile.encoding=UTF-8 jython-2.5.3.jar test.txt

目前都不能输入汉字



Published

Nov 23, 2010

Last Updated

Nov 23, 2010

Category

Tech

Tags

  • Jython 2
  • Windows 67
  • 字符串 2

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor