Hi,
I am looking for some pointers as to what I should look into to solve this strange behavior.
I have been trying to get a an RAP 3.1 based workbench application to run on Apache Karaf. The app has been running on equinox without issues. It's an OSGI deployment (no war). I finally got my RAP plugin (and all about 200 other bundles) to start, but I am having a hard time looking up other OSGI services from within the RAP plugin. I have never had this issue before and I can lookup these services from other bundles, but not the RAP bundle.
1) The following
FrameworkUtil.getBundle(SomeClassFromMyBundle.class)
returns always null. I debugged into getBundle() and the class loader of my class is different from the class loader of class BundleReference which is why it returns null.
2) If I save the bundle context from the activator's start() method in a static field and then try to lookup a service like
ServiceReference<PageMgr> pageMgrRef = UIActivator.bundleContext.getServiceReference(PageMgr.class);
then I get the following runtime exception:
java.lang.LinkageError: loader constraint violation: loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) previously initiated loading for a different type with name "org/osgi/framework/BundleContext" at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.defineClass(ModuleClassLoader.java:272)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.defineClass(ClasspathManager.java:632)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findClassImpl(ClasspathManager.java:588)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClassImpl(ClasspathManager.java:540)
at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:527)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:324)
at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:327)
at org.eclipse.osgi.internal.loader.sources.SingleSourcePackage.loadClass(SingleSourcePackage.java:36)
at org.eclipse.osgi.internal.loader.sources.MultiSourcePackage.loadClass(MultiSourcePackage.java:32)
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:398)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:352)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:344)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
...
Bundle A provides the services I want to access from my RAP bundle B. I have a workaround by importing a class from a different bundle C into my RAP plugin and the imported class provides methods that lookup the services via bundle C's context. This works.
Any ideas why I cannot do this directly in the RAP bundle?
Thanks,
Clemens