groovyConsole在启动时抛出java.lang.reflect.InvocationTargetException

时间:2013-04-16 02:44:45

标签: groovy groovy-console

我刚从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版“1.7.0_15”OpenJDK运行时环境(IcedTea7 2.3.7)   (7u15-2.3.7-0ubuntu1~12.10.1)OpenJDK服务器VM(版本23.7-b01,混合   模式)

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

1 个答案:

答案 0 :(得分:2)

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

  

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

这就是为什么你在运行groovyConsole时遇到java.awt.HeadlessException以及为什么你解决了安装Oracle JDK的问题,这个问题不是无头的(虽然你可以用无头模式运行带有java -Djava.awt.headless=true的java程序)。