Hi *, I'm currently working on getting Felix (5.6.8) embedded in an existing non-OSGI application. I'd like to force bundles to use several classes and packages already known to the application classloader. This is mainly due to memory- and classloading-footprint, but also greatly eases maintainance of bundles and their dependencies (well, for our limited purpose at least).
As far as I understood, there are two ways to archive this: either by using classloader-delegation or by providing org.osgi.framework.system.packages.extra. For now, we decided to use boot-delegation as it allows for use of wildcards, instead of specifying each an every (sub-)package. However, although the setup is straight-forward it simply does not work. For example, to provide global logging frameworks to all bundles: Map<Object, Object> configMap = new HashMap<Object, Object>(); // use the current classloader to provide logging configMap.put(Constants.FRAMEWORK_BOOTDELEGATION, "org.slf4j.*,ch.qos.logback.*"); configMap.put(Constants.FRAMEWORK_BUNDLE_PARENT, Constants.FRAMEWORK_BUNDLE_PARENT_APP); // more initialization ... Felix felix = new Felix(configMap); // there we go felix.start() Now, a bundle that gets installed and started just fine will throw CNF Exceptions as soon as a service class using org.slf4j... is instantiated, although those are provided by the application classloader. The stacktrace contains: Caused by: java.lang.ClassNotFoundException: *** Package 'org.slf4j' is not imported by bundle support-33x [1], nor is there any bundle that exports package 'org.slf4j'. However, the class 'org.slf4j.LoggerFactory' is available from the system class loader. There are two fixes: 1) Add package 'org.slf4j' to the 'org.osgi.framework.system.packages.extra' property and modify bundle support-33x [1] to import this package; this causes the system bundle to export class path packages. 2) Add package 'org.slf4j' to the 'org.osgi.framework.bootdelegation' property; a library or VM bug can cause classes to be loaded by the wrong class loader. The first approach is preferable for preserving modularity. *** at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2031) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 294 more Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory not found by support-33x [1] at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1610) at org.apache.felix.framework.BundleWiringImpl.access$200(BundleWiringImpl.java:80) at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018) Any idea, what went wrong or where to go from here? Thanks in advance! Kind regards, Max --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@felix.apache.org For additional commands, e-mail: users-h...@felix.apache.org