如何在Groovy Console(GroovyStarter)和GGTS / Eclipse控制台中输出和显示Unicode

时间:2012-12-28 04:59:53

标签: eclipse unicode groovy groovy-console

我想在floral formulae中通过我的DSL输出groovy,因此我需要一些特殊符号,例如female signSuperscripts and Subscripts

问题是Eclipse IDE(Groovy/Grails Tool Suite版本:3.1.0.RELEASE开发grails项目)和Groovy控制台(GroovyStarter)

给出这个样本groovy声明:

println '♀ Ca\u2075'

如果我从终端运行程序,我会在终端获得预期的输出:

$ groovy Testformula.groovy   
♀ Ca⁵

如果我从Groovy/Grails Tool Suite作为 Java应用程序运行它,但如果我将其作为 Groovy脚本或< em> Grovy控制台(Groovy启动器)我得到问号而不是unicode符号:

groovy> package org.rondakit.test 
groovy> class Testformula { 
groovy>     static void main(def args) { 
groovy>         println '\u2640' 
groovy>         println '♀ Ca\u2075' 
groovy>     } 
groovy> } 

我得到了令人讨厌的结果:

?
? Ca?

问题:是否可以在GGTS上配置 GroovyStarter Groovy Console 来显示unicode符号?

2 个答案:

答案 0 :(得分:6)

我找到了groovyConsole的解决方案,你需要输出&#34;导出JAVA_TOOL_OPTIONS = -Dfile.encoding = UTF-8&#34;到环境变量

答案 1 :(得分:2)

在GGTS下使用“Run as ...”Groovy Console或Groovy Script在我的盒子(ubuntu 12.04)中正常工作。您可能需要检查ggts中的配置。

默认情况下,Windows运行在cp1252编码上(今年某些项目中我们遇到了一些错误编码的问题)。 Linux默认为utf-8。我不确定OS X

相关问题