I am developing an Eclipse plugin and I try to replace a normal jar library with the equivalent OSGi bundle. I use the Apache Felix maven-bundle-plugin to build the jar file and convert it to an OSGi bundle. In the pom.xml I define the <Export-Package>
that I need for my plugin which uses
the javax.xml.namespace
package and also define as<Embed-Dependency>
all the packages (dependencies) that the library contained, including the javax.xml.namespace
package. When I was using the library in the classpath of the plugin I could run the plugin normally. Now, that I import the packages from the OSGi bundle that I created from the library, I get this error:
java.lang.LinkageError: loader constraint violation: loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) previously initiated loading for a different type with name "javax/xml/namespace/QName"
It seems like two different versions of the QName
class are instantiated (one from the plugin and one from the library?) but I need this class both in the library and the plugin. I tried importing the javax.xml.namespace package from the bundle into the plugin but this didn't help. Also I tried moving the code related to the library in another class of the plugin where I don't import the QName
class but this didn't change something. It seems like a tough problem. Do I need to change something in the MANIFEST.MF or in the embedded packages of the bundle or do I need to change something in the imported packages of the plugin? Any help is appreciated.