|
FAQ has been edited by Carsten Ziegeler (Jan 08, 2008). Content:Frequently Asked QuestionsThis page lists a series of common questions and answers. It is of course work in progress ...
Accessing Classes from the EnvironmentMostly when using the Sling Web Application, that is running Sling inside a web application deployed into some servlet container, you might want to share classes between the servlet container and Sling. Some examples of such sharing are:
For such cases the OSGi Core Specification provides a functionality to declare such class sharing. The functionality is defined in terms of two Framework properties org.osgi.framework.system.packages and org.osgi.framework.bootdelegation:
The problem with the org.osgi.framework.bootdelegation property is, that it completely bypasses any bundle import wirings and just asks the parent classloader. Such situations are not easily recognizable. Therefore the Sling Console will be enhanced to mark any package import which matchs an entry in the org.osgi.framework.bootdelegation appropriately (SLING-148 Also note, that any package listed as an import in a bundle must be resolveable for the bundle resolve. The import resolution process does not take the org.osgi.framework.bootdelegation configuration into account. This means, that regardless of whether a package is listed in the org.osgi.framework.bootdelegation property or not, if the package is listed as a required import in the Import-Package header, it must be exported by some other bundle. How does Sling support the org.osgi.framework.bootdelegation Property ?Sling supports the org.osgi.framework.bootdelegation property to list additional classes to be used from the environment by interpreting Sling configuration properties starting with sling.bootdelegation (This is done in the org.apache.sling.launcher.app.Sling.resolve() method). If a property starts with the prefix sling.bootdelegation.class. the list of packages defined as the property value is only appended to the org.osgi.framework.bootdelegation property if the fully qualified class taken from the rest of the property name exists in the parent class loader. If the property does not start with this sling.bootdelegation.class. property, the list of packages is just appended to the org.osgi.framework.bootdelegation property. How dose Sling support the org.osgi.framework.system.packages Property ?Currently extending the org.osgi.framework.system.packages property in a Sling configuration file is only possibly by setting the org.apache.sling.launcher.system.packages property. The value of this property, which must start with a comma, is just appended to the org.osgi.framewrok.system.packages property. A more elaborate support as is supported for the org.osgi.framework.bootdelegation Property is being prepared (SLING-147 Should the org.osgi.framework.bootdelegation or the org.osgi.framework.system.packages Property be used ?So, what mechanism should be used ? The answer is, that it depends. Most of the time, you will want to use the org.osgi.framework.system.packages property. Because this property ensures that you will allways benefit from the normal class resolution mechanism through package imports and exports. This allows creating the bundles normally by having the package import lists being built according to the packages used by the bundle classes. For example you may use the Apache Felix Maven Bundle Plugin to build your OSGi bundles and the imports are automatically calculated (by default). The drawback of this method is, that there may be bundles in your system, which export packages also listed in the org.osgi.framework.system.packages property. Depending on the export version, the wrong package may be bound. So to prevent such collisions you should not install such bundles. An example of such a declaration is the Servlet API packages (javax.servlet, javax.servlet.http and javax.servlet.resources). These packages are imported into the OSGi framework by the SlingServlet of the launcher/webapp project as part of the org.osgi.framework.system.packages property. To have this work correctly, no bundle should export the respective packages. In the case of Sling, this means, the org.apache.felix.commons.sling-api bundle must not be installed. If on the other hand you cannot prevent the installation of such bundles and hence the export of the respective packages, you might want to set the org.osgi.framework.bootdelegation property conditionally as described above in the answer to how this property is supported in Sling. This ensures the property is only set, if the classes are actually available. This should be used as a fall back only, if the org.osgi.framework.system.packages method does not work. Is there an easy way to update bundles in a running installation during development?The Sling Maven Plugin provides an install goal which is able to install or update a bundle in a running Sling application (if the Sling web console is deployed). If the plugin properties are configured accordingly you can just mvn clean package org.apache.sling:maven-sling-plugin:install and the bundle is uploaded. You can use the settings.xml to set the url to your Sling application. See the Sling Maven Plugin for more information. |
Unsubscribe or edit your notifications preferences
