无法启动 Groovy 控制台

Cannot launch the Groovy Console

我刚刚通过 GVM 工具在 OSX 10.10.3 中全新安装了 Groovy 2.4.3。 我还使用 GVM 安装了相关的库和工具,例如 groovyserv、grails 和 gradle。 我使用的 Java 版本是 1.8.0_25.

一切似乎都很好,除了我无法通过命令 groovyConsole 启动 Groovy 控制台,因为我不断收到此异常:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:106)
    at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)
Caused by: javax.xml.parsers.FactoryConfigurationError: Provider for javax.xml.parsers.SAXParserFactory cannot be found
    at javax.xml.parsers.SAXParserFactory.newInstance(Unknown Source)
    at org.apache.ivy.core.settings.XmlSettingsParser.doParse(XmlSettingsParser.java:160)
    at org.apache.ivy.core.settings.XmlSettingsParser.parse(XmlSettingsParser.java:150)
    at org.apache.ivy.core.settings.IvySettings.load(IvySettings.java:417)
    at org.apache.ivy.core.settings.IvySettings$load.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:122)
    at groovy.grape.GrapeIvy.<init>(GrapeIvy.groovy:96)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at java.lang.Class.newInstance(Class.java:438)
    at groovy.grape.Grape.getInstance(Grape.java:117)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
    at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1844)
    at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3734)
    at org.codehaus.groovy.runtime.callsite.ClassMetaClassGetPropertySite.getProperty(ClassMetaClassGetPropertySite.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:293)
    at groovy.ui.ConsoleIvyPlugin.addListener(ConsoleIvyPlugin.groovy:41)
    at groovy.ui.ConsoleIvyPlugin$addListener.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:110)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:122)
    at groovy.ui.Console.<init>(Console.groovy:239)
    at groovy.ui.Console.<init>(Console.groovy:221)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
    at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:232)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:244)
    at groovy.ui.Console.main(Console.groovy:206)
    ... 6 more

解决此问题的最佳方法是什么?

我以前有过这个,这是由于环境类路径变量设置为指向无效的 jar

我也有同样的问题。在我的例子中 JAVA_HOME 路径是错误的。所以我设置 JAVA_HOME 然后它的工作没有任何问题。

设置JAVA_HOME后,启动: