3

我刚刚从 Ubuntu 的软件中心在 Ubuntu Studio 12.10 中安装了 groovy,我正在尝试运行 GroovyConsole,但是当我执行“groovyConsole”时会引发异常:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108)
    at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130)
Caused by: java.awt.HeadlessException
    at sun.awt.HeadlessToolkit.getMenuShortcutKeyMask(HeadlessToolkit.java:237)
    at sun.awt.HeadlessToolkit$getMenuShortcutKeyMask.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
    at groovy.swing.SwingBuilder.shortcut(SwingBuilder.groovy:379)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSite.invoke(PogoMetaMethodSite.java:226)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:52)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:145)
    at groovy.swing.SwingBuilder.shortcut(SwingBuilder.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1047)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877)
    at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:793)
    at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:776)
    at groovy.util.FactoryInterceptorMetaClass.invokeMethod(FactoryBuilderSupport.java:1287)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
    at groovy.ui.ConsoleActions.run(ConsoleActions.groovy:27)
    at groovy.util.FactoryBuilderSupport.build(FactoryBuilderSupport.java:1123)
    at groovy.util.FactoryBuilderSupport.build(FactoryBuilderSupport.java:1106)
    at groovy.util.FactoryBuilderSupport$build.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
    at groovy.ui.Console.run(Console.groovy:298)
    at groovy.ui.Console$run$0.callCurrent(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
    at groovy.ui.Console.run(Console.groovy:264)
    at groovy.ui.Console$run.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
    at groovy.ui.Console.main(Console.groovy:199)
    ... 6 more

我有openJDK

java version "1.7.0_15" OpenJDK Runtime Environment (IcedTea7 2.3.7) (7u15-2.3.7-0ubuntu1~12.10.1) OpenJDK Server VM (build 23.7-b01, 混合模式)

groovysh 和 groovy 命令工作正常。有什么建议可以让它发挥作用吗?

4

1 回答 1

3

您可能已经安装了“无头”Java,即没有图形库。

无头模式是缺少显示设备、键盘或鼠标的系统配置。听起来很意外,但实际上您可以在此模式下执行不同的操作,即使是图形数据。

这就是为什么您在java.awt.HeadlessException使用它运行 groovyConsole 时遇到问题的原因,以及为什么您解决了安装非无头的 Oracle JDK 的问题(尽管您可以使用 以无头模式运行 java 程序java -Djava.awt.headless=true)。

于 2013-04-17T13:49:32.703 回答