Additionally, when you use: org.osgi.framework.system.packages.extra
though it's slightly more verbose, it means the bundles you've built will more likely have proper metadata. Some benefits of which are: - moving the provider of those packages around without changing the consuming bundles - run in a more pure OSGi environment - support assembling applications from your bundles using the OSGi resolver - etc. Cheers - Ray On Thu, Oct 12, 2017 at 9:07 AM, Karl Pauls <karlpa...@gmail.com> wrote: > Hi Max, > > I think you are using the wrong FRAMEWORK_BUNDLE_PARENT. In your > example, you use: FRAMEWORK_BUNDLE_PARENT_APP - which happens to be > the system classloader. I would guess you want > FRAMEWORK_BUNDLE_PARENT_FRAMEWORK - which would be the classloader > that loaded the framework. > > Does this help? > > regards, > > Karl > > On Thu, Oct 12, 2017 at 2:36 PM, Maximilian Schmidt > <maximilian.schm...@secunet.com> wrote: > > 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 > > > > > > -- > Karl Pauls > karlpa...@gmail.com > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@felix.apache.org > For additional commands, e-mail: users-h...@felix.apache.org > > -- *Raymond Augé* <http://www.liferay.com/web/raymond.auge/profile> (@rotty3000) Senior Software Architect *Liferay, Inc.* <http://www.liferay.com> (@Liferay) Board Member & EEG Co-Chair, OSGi Alliance <http://osgi.org> (@OSGiAlliance)