Search code examples
javaeclipse-rcposgi-bundleosgi-fragment

eclipse4 RCP Fragment "Unable to load class from bundle"


I currently try to migrate an Eclipse 3 RCP application to e4. The project is based on a main plugin project and several fragment projects. I'm using Eclipse Mars for developing. The following description is based on a sample project I created for this.

The main application provides a simple menu with some handled menu items. The fragment should add some more menu items to this. But I get an exception telling me, that the assigned handler class could not be loaded:

!ENTRY org.eclipse.e4.ui.workbench 4 0 2015-10-15 17:44:04.540
!MESSAGE Unable to load class 'de.fragment.Handler' from bundle '61'
!STACK 0
java.lang.ClassNotFoundException: Can not load a class from a fragment bundle: E4TestFragment_1.0.0.qualifier [61]

The structures of the both projects are more or less like follows.

Main application (eclipse PlugIn-Project):

  • META-INF/MANIFEST.MF
  • Application.e4xmi
  • plugin.xml

MANIFEST.MF content:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: E4Test3
Bundle-SymbolicName: E4Test3;singleton:=true
Bundle-Version: 1.0.0.qualifier
Require-Bundle: javax.inject;bundle-version="1.0.0",
 org.eclipse.core.runtime;bundle-version="3.11.0",
 org.eclipse.swt;bundle-version="3.104.0",
 org.eclipse.e4.ui.model.workbench;bundle-version="1.1.100",
 org.eclipse.jface;bundle-version="3.11.0",
 org.eclipse.e4.ui.services;bundle-version="1.2.0",
 org.eclipse.e4.ui.workbench;bundle-version="1.3.0",
 org.eclipse.e4.core.di;bundle-version="1.5.0",
 org.eclipse.e4.ui.di;bundle-version="1.1.0",
 org.eclipse.e4.core.contexts;bundle-version="1.4.0",
 org.eclipse.e4.ui.workbench.swt;bundle-version="0.13.0",
 org.eclipse.e4.ui.workbench.renderers.swt;bundle-version="0.13.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ClassPath: .

Fragment (eclipse Fragment-Project):

  • de/fragment/Handler.java
  • META-INF/MANIFEST.MF
  • fragment.e4xmi
  • fragment.xml

MANIFEST.MF content:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: E4TestFragment
Bundle-SymbolicName: E4TestFragment;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Fragment-Host:  E4Test3;bundle-version="1.0.0"
Export-Package: de.fragment
Bundle-ClassPath: .

The fragment.e4xmi itself is evaluated correctly. I checked this by removing the handler from the menu item which then just adds the icon to the gui.

Honestly I have no idea what could cause this exception. Does anyone of you have an idea and could help me?

Thanks in advance


Solution

  • I think you may be confusing two meanings of 'fragment' in Eclipse plugins.

    You have a fragment.e4xmi which is the e4 meaning of 'fragment' - a fragment of the e4 model.

    You have then put this in a 'fragment' plugin. Fragment plugins are a different meaning of fragment and are not normal plugins. In fact they are not separate plugins at all (instead they are just part of the host plugin).

    Change your E4TestFragment to be a normal plugin.