Eclipse PDE : java.lang.NoClassDefFoundError: org/eclipse/core/resources/ResourcesPlugin

Eclipse PDE : java.lang.NoClassDefFoundError: org/eclipse/core/resources/ResourcesPlugin

我有一个 Eclipse 应用程序,在执行时出现以下错误 -

java.lang.NoClassDefFoundError: org/eclipse/core/resources/ResourcesPlugin
    at org.eclipse.emf.ecore.plugin.EcorePlugin.getWorkspaceRoot(EcorePlugin.java:1149)
    at org.eclipse.emf.ecore.resource.impl.PlatformResourceURIHandlerImpl.getWorkspaceRoot(PlatformResourceURIHandlerImpl.java:488)
    at org.eclipse.emf.ecore.resource.impl.PlatformResourceURIHandlerImpl.<clinit>(PlatformResourceURIHandlerImpl.java:456)
    at org.eclipse.emf.ecore.resource.URIHandler.<clinit>(URIHandler.java:51)
    at org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.<init>(ExtensibleURIConverterImpl.java:138)
    at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getURIConverter(ResourceSetImpl.java:499)
    at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:369)
    at com.act21.mamba.modelserver.codec.MambaXMICodec.decode(MambaXMICodec.java:94)
    at com.act21.mamba.modelserver.codec.MambaXMICodec.decode(MambaXMICodec.java:65)
    at com.act21.mamba.modelserver.codec.MambaXMICodec.decode(MambaXMICodec.java:57)
    at com.act21.mamba.modelserver.MambaModelServerClient.decode(MambaModelServerClient.java:59)
    at org.eclipse.emfcloud.modelserver.client.ModelServerClient.lambda(ModelServerClient.java:116)
    at java.base/java.util.Optional.flatMap(Optional.java:294)
    at org.eclipse.emfcloud.modelserver.client.ModelServerClient.lambda(ModelServerClient.java:116)
    at java.base/java.util.function.Function.lambda$andThen(Function.java:88)
    at java.base/java.util.function.Function.lambda$andThen(Function.java:88)
    at org.eclipse.emfcloud.modelserver.client.Response.body(Response.java:39)
    at com.act21.mamba.common.ModelServerClientUtil.loadResource(ModelServerClientUtil.java:25)
    at com.act21.mamba.common.ModelServerClientUtil.loadResource(ModelServerClientUtil.java:34)
    at com.act21.mamba.codegen.application.Application.generate(Application.java:85)
    at com.act21.mamba.codegen.application.Application.start(Application.java:58)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
    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:657)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:594)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
Caused by: java.lang.ClassNotFoundException: An error occurred while automatically activating bundle org.eclipse.core.resources (28).
    at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:126)
    at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:572)
    at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:346)
    at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:398)
    at org.eclipse.osgi.internal.loader.sources.SingleSourcePackage.loadClass(SingleSourcePackage.java:41)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:473)
    at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:171)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 34 more
Caused by: org.osgi.framework.BundleException: Exception in org.eclipse.core.resources.ResourcesPlugin.start() of bundle org.eclipse.core.resources.
    at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:835)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:763)
    at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:1011)
    at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:365)
    at org.eclipse.osgi.container.Module.doStart(Module.java:605)
    at org.eclipse.osgi.container.Module.start(Module.java:468)
    at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:506)
    at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:117)
    ... 41 more
Caused by: java.lang.NullPointerException
    at org.eclipse.core.internal.resources.CharsetDeltaJob.startup(CharsetDeltaJob.java:212)
    at org.eclipse.core.internal.resources.CharsetManager.startup(CharsetManager.java:505)
    at org.eclipse.core.internal.resources.Workspace.startup(Workspace.java:2456)
    at org.eclipse.core.internal.resources.Workspace.open(Workspace.java:2210)
    at org.eclipse.core.resources.ResourcesPlugin.start(ResourcesPlugin.java:489)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.run(BundleContextImpl.java:814)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.run(BundleContextImpl.java:1)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:806)
    ... 48 more

我在插件和产品配置的清单中都包含 org.eclipse.core.resources -

1.Manifest 的插件 -

Require-Bundle: org.apache.log4j;bundle-version="1.2.15",
 org.apache.commons.io;bundle-version="[2.6.0,3.0.0)",
 com.google.inject;bundle-version="3.0.0",
 com.google.guava,
 org.eclipse.emf.common,
 org.eclipse.emf.ecore.xmi,
 org.eclipse.emfcloud.modelserver.client;bundle-version="0.7.0",
 org.eclipse.emfcloud.modelserver.common;bundle-version="0.7.0",
 org.eclipse.emfcloud.modelserver.edit;bundle-version="0.7.0",
 org.eclipse.emfcloud.modelserver.emf;bundle-version="0.7.0",
 org.eclipse.emfcloud.modelserver.lib;bundle-version="0.7.0",
 org.slf4j.api;bundle-version="1.7.30",
 org.eclipse.glsp.graph;bundle-version="0.9.0",
 org.eclipse.emf.edit;bundle-version="2.16.0",
 org.eclipse.emf.transaction;bundle-version="1.9.1",
 com.fasterxml.jackson.core.jackson-annotations;bundle-version="2.10.3",
 com.fasterxml.jackson.core.jackson-core;bundle-version="2.10.3",
 com.fasterxml.jackson.core.jackson-databind;bundle-version="2.10.3",
 com.act21.mamba.model;bundle-version="1.0.0",
 javax.inject;bundle-version="1.0.0",
 org.emfjson.jackson;bundle-version="1.2.0",
 javax.servlet;bundle-version="3.1.0",
 org.eclipse.jetty.util;bundle-version="9.4.37",
 org.eclipse.jetty.http;bundle-version="9.4.37",
 org.eclipse.jetty.io;bundle-version="9.4.37",
 org.eclipse.jetty.security;bundle-version="9.4.37",
 org.eclipse.jetty.server;bundle-version="9.4.37",
 org.eclipse.jetty.servlet;bundle-version="9.4.37",
 org.eclipse.jetty.websocket.api;bundle-version="9.4.37",
 org.eclipse.jetty.websocket.common;bundle-version="9.4.37",
 org.eclipse.jetty.websocket.server;bundle-version="9.4.37",
 org.eclipse.jetty.websocket.servlet;bundle-version="9.4.37",
 org.eclipse.core.resources;bundle-version="3.13.800"

2.Product配置-

<?xml version="1.0" encoding="UTF-8"?>
<?pde version="3.5"?>

<product name="Code gen" uid="com.act21.mamba.product.codegen" id="com.act21.mamba.codegen.application.product" application="com.act21.mamba.codegen.application.application" version="0.1.0" useFeatures="false" includeLaunchers="true">

   <configIni use="default">
   </configIni>

   <launcherArgs>
      <programArgs>-consoleLog
      </programArgs>
      <vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts
      </vmArgsMac>
   </launcherArgs>

   <windowImages/>

   <launcher>
      <win useIco="false">
         <bmp/>
      </win>
   </launcher>

   <vm>
      <linux include="false">org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11</linux>
      <windows include="false">org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11</windows>
   </vm>

   <plugins>
      <plugin id="ch.qos.logback.classic"/>
      <plugin id="ch.qos.logback.core"/>
      <plugin id="ch.qos.logback.slf4j" fragment="true"/>
      <plugin id="com.act21.mamba.codegen"/>
      <plugin id="com.act21.mamba.codegen.application"/>
      <plugin id="com.act21.mamba.common"/>
      <plugin id="com.act21.mamba.model"/>
      <plugin id="com.act21.mamba.modelserver"/>
      <plugin id="com.fasterxml.jackson.core.jackson-annotations"/>
      <plugin id="com.fasterxml.jackson.core.jackson-core"/>
      <plugin id="com.fasterxml.jackson.core.jackson-databind"/>
      <plugin id="com.google.gson"/>
      <plugin id="com.google.guava"/>
      <plugin id="com.google.inject"/>
      <plugin id="com.google.inject.multibindings" fragment="true"/>
      <plugin id="com.ibm.icu"/>
      <plugin id="javax.inject"/>
      <plugin id="javax.servlet"/>
      <plugin id="org.apache.commons.io"/>
      <plugin id="org.apache.commons.lang"/>
      <plugin id="org.apache.log4j"/>
      <plugin id="org.eclipse.core.contenttype"/>
      <plugin id="org.eclipse.core.expressions"/>
      <plugin id="org.eclipse.core.filesystem"/>
      <plugin id="org.eclipse.core.filesystem.win32.x86_64" fragment="true"/>
      <plugin id="org.eclipse.core.jobs"/>
      <plugin id="org.eclipse.core.resources"/>
      <plugin id="org.eclipse.core.resources.win32.x86_64" fragment="true"/>
      <plugin id="org.eclipse.core.runtime"/>
      <plugin id="org.eclipse.emf.common"/>
      <plugin id="org.eclipse.emf.ecore"/>
      <plugin id="org.eclipse.emf.ecore.change"/>
      <plugin id="org.eclipse.emf.ecore.xmi"/>
      <plugin id="org.eclipse.emf.edit"/>
      <plugin id="org.eclipse.emf.transaction"/>
      <plugin id="org.eclipse.emf.validation"/>
      <plugin id="org.eclipse.emfcloud.modelserver.client"/>
      <plugin id="org.eclipse.emfcloud.modelserver.common"/>
      <plugin id="org.eclipse.emfcloud.modelserver.edit"/>
      <plugin id="org.eclipse.emfcloud.modelserver.emf"/>
      <plugin id="org.eclipse.emfcloud.modelserver.lib"/>
      <plugin id="org.eclipse.equinox.app"/>
      <plugin id="org.eclipse.equinox.common"/>
      <plugin id="org.eclipse.equinox.preferences"/>
      <plugin id="org.eclipse.equinox.registry"/>
      <plugin id="org.eclipse.glsp.graph"/>
      <plugin id="org.eclipse.jetty.http"/>
      <plugin id="org.eclipse.jetty.io"/>
      <plugin id="org.eclipse.jetty.security"/>
      <plugin id="org.eclipse.jetty.server"/>
      <plugin id="org.eclipse.jetty.servlet"/>
      <plugin id="org.eclipse.jetty.util"/>
      <plugin id="org.eclipse.jetty.util.ajax"/>
      <plugin id="org.eclipse.jetty.websocket.api"/>
      <plugin id="org.eclipse.jetty.websocket.common"/>
      <plugin id="org.eclipse.jetty.websocket.server"/>
      <plugin id="org.eclipse.jetty.websocket.servlet"/>
      <plugin id="org.eclipse.osgi"/>
      <plugin id="org.eclipse.osgi.compatibility.state" fragment="true"/>
      <plugin id="org.eclipse.osgi.services"/>
      <plugin id="org.eclipse.osgi.util"/>
      <plugin id="org.eclipse.xtend.lib"/>
      <plugin id="org.eclipse.xtend.lib.macro"/>
      <plugin id="org.eclipse.xtext.logging" fragment="true"/>
      <plugin id="org.eclipse.xtext.xbase.lib"/>
      <plugin id="org.emfjson.jackson"/>
      <plugin id="org.slf4j.api"/>
   </plugins>

   <configurations>
      <plugin id="org.eclipse.core.runtime" autoStart="true" startLevel="0" />
      <plugin id="org.eclipse.equinox.common" autoStart="true" startLevel="2" />
      <plugin id="org.eclipse.osgi" autoStart="true" startLevel="-1" />
   </configurations>

   <preferencesInfo>
      <targetfile overwrite="false"/>
   </preferencesInfo>

   <cssInfo>
   </cssInfo>

</product>

我不确定为什么它仍然找不到 org.eclipse.core.resources.ResourcesPlugin class.

日志显示正在找到 ResourcesPlugin,但其插件激活器在尝试获取 IContentTypeManager.

时出现空指针异常

内容类型管理器是使用 OSGi 声明性服务提供的,但您没有包含处理此问题的 org.apache.felix.scr

因此您至少需要包含 org.apache.felix.scr 并在 <configurations> 部分启动它:

     <plugin id="org.apache.felix.scr" autoStart="true" startLevel="2" />