/** * Allow to this bundle/elements to be visible and accessible from the host classpath * * @param context * @throws Exception */ protected void publishBundleServices(BundleContext context) throws Exception { // Classloaders ClassLoader felixClassLoader = getFelixClassLoader(); ClassLoader contextClassLoader = getContextClassLoader(); // Create a new class loader where we can "combine" our classloaders CombinedLoader combinedLoader; if (contextClassLoader instanceof CombinedLoader) { combinedLoader = (CombinedLoader) contextClassLoader; combinedLoader.addLoader(felixClassLoader); } else { combinedLoader = new CombinedLoader(contextClassLoader); combinedLoader.addLoader(felixClassLoader); } // Force the loading of some classes that may be already loaded on the host classpath but we // want to override with the ones on this bundle and we specified String overrideClasses = activatorUtil.getManifestHeaderValue(context, MANIFEST_HEADER_OVERRIDE_CLASSES); if (overrideClasses != null && !overrideClasses.isEmpty()) { String[] forceOverride = overrideClasses.split(","); if (forceOverride.length > 0) { try { // Get the activator class for this OSGI bundle String activatorClass = activatorUtil.getManifestHeaderValue(context, MANIFEST_HEADER_BUNDLE_ACTIVATOR); // Injecting this bundle context code inside the dotCMS context injectContext(activatorClass); } catch (Exception e) { Logger.error(this, "Error injecting context for overriding", e); throw e; } for (String classToOverride : forceOverride) { try { /* Loading the custom implementation will allows to override the one the ClassLoader already had loaded and use it on this OSGI bundle context */ combinedLoader.loadClass(classToOverride.trim()); } catch (Exception e) { Logger.error(this, "Error overriding class: " + classToOverride, e); throw e; } } } } // Use this new "combined" class loader Thread.currentThread().setContextClassLoader(combinedLoader); }