Eclipse 安装了 Groovy 开发插件之后,双击打不开 .java 文件了

我在 Eclipse 里打开我的 Java 项目,双击一个 .java 文件,遇到错误消息:Failed to create the part's control

错误调用栈如下图所示:

java.lang.NoClassDefFoundError: org/codehaus/groovy/eclipse/editor/GroovyAwareFoldingStructureProvider at org.codehaus.groovy.eclipse.GroovyPlugin1.getCurrentFoldingProvider(GroovyPlugin.java:182) at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.createSourceViewer(JavaEditor.java:1891) at org.eclipse.ui.texteditor.AbstractTextEditor.createPartControl(AbstractTextEditor.java:3369) at org.eclipse.ui.texteditor.StatusTextEditor.createPartControl(StatusTextEditor.java:64) at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.createPartControl(AbstractDecoratedTextEditor.java:454) at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.createPartControl(JavaEditor.java:3093) at org.eclipse.jdt.internal.ui.javaeditor.compilationunitEditor.createPartControl(compilationunitEditor.java:1521) at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(CompatibilityPart.java:158) at org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor.createPartControl(CompatibilityEditor.java:96) at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:365) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:58) at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:995) at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:960) at org.eclipse.e4.core.internal.di.InjectorImpl.internalInject(InjectorImpl.java:140) at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:403) at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:330) at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:202) at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:91) at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:60) at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:42) at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java:132) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:994) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:658) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:762) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine2.run(PartRenderingEngine.java:727) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:711) at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.lambda

at org.eclipse.e4.ui.services.internal.events.UIEventHandler.lambda$0(UIEventHandler.java:38)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:236)
at org.eclipse.ui.internal.Uisynchronizer.syncExec(Uisynchronizer.java:133)
at org.eclipse.swt.widgets.display.syncExec(display.java:4779)
at org.eclipse.e4.ui.workbench.swt.displayUisynchronize.syncExec(displayUisynchronize.java:34)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:38)
at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:205)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:203)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:228)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:151)
at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:133)
at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:75)
at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:44)
at org.eclipse.e4.ui.services.internal.events.Eventbroker.send(Eventbroker.java:55)
at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:63)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:424)
at org.eclipse.e4.ui.model.application.ui.impl.ElementContainerImpl.setSelectedElementGen(ElementContainerImpl.java:170)
at org.eclipse.e4.ui.model.application.ui.impl.ElementContainerImpl.setSelectedElement(ElementContainerImpl.java:188)
at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.showElementInWindow(ModelServiceImpl.java:660)
at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.bringToTop(ModelServiceImpl.java:624)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.delegateBringToTop(PartServiceImpl.java:787)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.bringToTop(PartServiceImpl.java:401)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.showPart(PartServiceImpl.java:1261)
at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:3208)
at org.eclipse.ui.internal.WorkbenchPage.lambda$9(WorkbenchPage.java:3112)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:74)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3110)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3080)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3071)
at org.eclipse.ui.ide.IDE.openEditor(IDE.java:569)
at org.eclipse.ui.ide.IDE.openEditor(IDE.java:524)
at org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInEditor(EditorUtility.java:367)
at org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInEditor(EditorUtility.java:172)
at org.eclipse.jdt.ui.actions.OpenAction.run(OpenAction.java:288)
at org.eclipse.jdt.ui.actions.OpenAction.run(OpenAction.java:254)
at org.eclipse.jdt.ui.actions.SelectiondispatchAction.dispatchRun(SelectiondispatchAction.java:274)
at org.eclipse.jdt.ui.actions.SelectiondispatchAction.run(SelectiondispatchAction.java:252)
at org.eclipse.jdt.internal.ui.packageview.PackageExplorerActionGroup.handleOpen(PackageExplorerActionGroup.java:366)
at org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart$3.open(PackageExplorerPart.java:545)
at org.eclipse.ui.OpenAndLinkWithEditorHelper$InternalListener.open(OpenAndLinkWithEditorHelper.java:48)
at org.eclipse.jface.viewers.StructuredViewer$2.run(StructuredViewer.java:800)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:174)
at org.eclipse.jface.viewers.StructuredViewer.fireOpen(StructuredViewer.java:797)
at org.eclipse.jface.viewers.StructuredViewer.handleOpen(StructuredViewer.java:1116)
at org.eclipse.jface.util.OpenStrategy.fireOpenEvent(OpenStrategy.java:296)
at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:331)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
at org.eclipse.swt.widgets.display.sendEvent(display.java:4243)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1060)
at org.eclipse.swt.widgets.display.runDeferredEvents(display.java:4060)
at org.eclipse.swt.widgets.display.readAnddispatch(display.java:3632)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1154)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1045)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:644)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:551)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:156)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:136)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:659)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:596)
at org.eclipse.equinox.launcher.Main.run(Main.java:1467)

参看 Eclipse 的 bug 列表: https://bugs.eclipse.org/bugs/show_bug.cgi?id=577806

It seems that you have installed the Groovy Development tools, or at least some of the plugins of that project.

Their project overrides the getCurrentFoldingProvider method using reflection, that causes this error. https://github.com/groovy/groovy-eclipse/blob/master/ide/org.codehaus.groovy.eclipse.ui/src/org/codehaus/groovy/eclipse/GroovyPlugin.java#L177

This issue is reported at the Groovy Eclipse plugin: https://github.com/groovy/groovy-eclipse/issues/1319

如果 Eclipse 安装了 Eclipse Groovy Development ToolsGroovy compiler 3.0, 就会出现这个错误,因为 Groovy 插件通过 Java reflection 机制,复写了 getCurrentFoldingProvider,导致的 bug:

我把上图所示的两个黄色插件从 Eclipse 里卸载,就又可以重新打开 Java 文件了:

更详细的 Groovy plugin 信息:

Pivotal Software, Inc. Apache Groovy 2.5.14.v202103311613-e2103-RELEASE org.codehaus.groovy Pivotal Software, Inc. Groovy Ant support 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse.ant Pivotal Software, Inc. Groovy AST Views 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse.astviews Pivotal Software, Inc. Groovy Code Assist 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse.codeassist Pivotal Software, Inc. Groovy Code browsing 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse.codebrowsing Pivotal Software, Inc. Groovy Compiler Resolver 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse.compilerResolver Pivotal Software, Inc. Groovy Core 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse.core Pivotal Software, Inc. Groovy DSL support 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse.dsl Pivotal Software, Inc. Groovy-Eclipse 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse Pivotal Software, Inc. Groovy-Eclipse integration 4.1.0.v202103311613-e2103-RELEASE org.eclipse.jdt.groovy.core Pivotal Software, Inc. Groovy Quick Fix 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse.quickfix Pivotal Software, Inc. Groovy Refactoring 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse.refactoring Pivotal Software, Inc. Groovy UI 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse.ui

如果想保留 Groovy 插件解决方案参考如下:

In our project (Apache OFBiz) we still use Groovy 2.5.11, so I tried to install GDT 3.5.0. Eclipse refused and suggested something else. It worked. I have Now a mix of installed versions (3 4.50 and 1 4.40) but at least it works

相关文章

Java中的String是不可变对象 在面向对象及函数编程语言中,不...
String, StringBuffer 和 StringBuilder 可变性 String不可变...
序列化:把对象转换为字节序列的过程称为对象的序列化. 反序...
先说结论,是对象!可以继续往下看 数组是不是对象 什么是对...
为什么浮点数 float 或 double 运算的时候会有精度丢失的风险...
面试题引入 这里引申出一个经典问题,看下面代码 Integer a ...