Apache Felix SCR Annotations BndTools Use :: Apache Felix Home Subprojects Dependency Manager Event Admin File Install Framework Gogo Shell Health Checks Inventory Log Logback Maven bundle plugin Maven SCR plugin Metatype Service Preferences Service Remote Shell Script console plugin Lightweight shell Shell TUI Web Console Downloads Documentation Documentation Downloads Getting Started News Community Apache Felix Project Info Contributing Projects Using Felix Development Coding Standards DEPENDENCIES file template Provisional OSGi API Policy Release Management Site How To Using the OSGi Compliance Tests FAQS Apache Felix Bundle Plugin Frequently Asked Questions Apache Felix SCR Plugin Frequently Asked Questions Subprojects Apache Felix Dependency Manager Guides Apache Felix Dependency Manager - Migrating from earlier versions Dependency Manager - Annotations Dependency Manager - Background Dependency Manager - Bundles and Dependencies Dependency Manager - Design Patterns Dependency Manager - Development Dependency Manager - History Dependency Manager - JavaDocs Dependency Manager - Migrating from other solutions. Dependency Manager - Performance Tuning Dependency Manager - Resource adapters Dependency Manager - What’s new in version 4? Dependency Manager Lambda What’s New in R15 Reference Dependency Manager - Adapter Dependency Manager - Aspect Dependency Manager - Bundle Adapter Dependency Manager - Bundle Dependency Dependency Manager - Components Dependency Manager - Configuration Dependency Dependency Manager - Dependencies Dependency Manager - External Links Dependency Manager - Factory Configuration Adapter Service Dependency Manager - Resource Adapter Dependency Manager - Resource Dependency Dependency Manager - Service Dependency Dependency Manager - Service Scopes Dependency Manager - Singleton Component Dependency Manager - Thread Model Dependency Manager Annotations Tutorials Dependency Manager - Annotations Dependency Manager - Getting Started Dependency Manager - Leveraging the shell Dependency Manager sample projects Apache Felix Event Admin Apache Felix File Install Apache Felix Framework Apache Felix Framework Bundle Cache Apache Felix Framework Configuration Properties Apache Felix Framework Frequently Asked Questions Apache Felix Framework Launching and Embedding Apache Felix Framework Usage Documentation Apache Felix Framework Security Apache Felix Gogo RFC 147 Overview Apache Felix Health Checks Apache Felix Inventory Printer Apache Felix Log Apache Felix Logback Apache Felix Maven Bundle Plugin (BND) Apache Felix Metatype Service Apache Felix OSGi Bundle Repository (OBR) Apache Felix Preferences Service Apache Felix Remote Shell Apache Felix Shell Apache Felix Shell TUI Apache Felix Web Console Extending the Apache Felix Web Console Web Console RESTful API Web Console Security Provider Extensions Branding the Web Console Providing Resources Providing Web Console Plugins Web Console Logging Web Console Output Templating Tutorials Apache Felix Application Demonstration Apache Felix OSGi Tutorial OSGi Frequently Asked Questions OSGI Tutorial Apache Felix Tutorial Example 1 - Service Event Listener Bundle Apache Felix Tutorial Example 2 Apache Felix Tutorial Example 2b Apache Felix Tutorial Example 3 Apache Felix Tutorial Example 4 Apache Felix Tutorial Example 5 Example 6 - Spell Checker Service Bundle Example 7 - Spell Checker Client Bundle Example 8 - Spell Checker Service using Service Binder Example 9 - Spell Checker Service using Declarative Services Apache License 2.0 Site map Documentation master Documentation master Documentation Apache Felix SCR Annotations BndTools Use Edit this Page Apache Felix SCR Annotations BndTools Use The Apache Felix SCR Tooling is not supported anymore. Please use the official OSGi annotations and bnd based tooling instead. Using the Apache Felix SCR Annotations Bnd plugin to generate Declarative Services and Metatype Service descriptors in BndTools. The org.apache.felix.scrplugin.bnd.SCRDescriptorBndPlugin is a bnd plugin allowing to generate SCR annotations and metatype descriptors in the Eclipse BndTools environment. This page describes how to install the plugin in BndTools and also provides a simple tutorial, which won’t be very fascinating, but will make it easy to demonstrate the use of Apache SCR annotations within BndTools. If you are not yet familiar with BndTools or if you have not already installed it, you can take a look at BndTools homepage. This tutorial has been made with Eclipse Kepler and with the latest BndTools development version. It is assumed that the eclipse workspace is currently set to ~/workspace/BNDTOOLS Installing SCR Bnd plugin in BndTools Create the cnf project: If the BndTools "cnf" project does not already exist in your workspace, then create it: In the Eclipse Windows menu, click on Preference -> BndTools OSGi Click on "Configuration Project/Check Now". This will create the "cnf" bndtools project. Compile the SCR annotations bnd plugin and copy it in cnf project: Now you have to copy the SCR annotations bnd plugin into the cnf project of your current workspace ("BNDTOOLS" in this example). For now, the plugin is not yet released, but you can build it yourself like this: $ svn checkout http://svn.apache.org/repos/asf/felix/trunk/scrplugin scrplugin $ cd scrplugin $ mvn clean install $ mkdir ~/workspace/BNDTOOLS/cnf/plugins/org.apache.felix.scr.bnd/ $ cp scrplugin/bnd-scr-plugin/target/org.apache.felix.scr.bnd-X.Y.Z-SNAPSHOT.jar ~/workspace/BNDTOOLS/cnf/plugins/org.apache.felix.scr.bnd/ Configure the default BndTools plugin path: In order to let BndTools load the SCR annotations bnd plugin, you can configure the default BndTools plugin path: First, if you have not yet opened the BndTools perspective, then open it: go to Window Menu -> Open Perspective -> BndTools. Now, in BndTools menu, click on "BndTools Open ext/pluginpaths.bnd", then click on "Source" and append the SCR bnd plugin (${plugin-dir}/org.apache.felix.scr.bnd/org.apache.felix.scr.bnd-X.Y.Z-SNAPSHOT.jar) to the current plugin path. For example: -pluginpath: ${plugin-dir}/biz.aQute.repository/biz.aQute.repository-2.1.0.jar, \ ${plugin-dir}/org.apache.felix.scr.bnd/org.apache.felix.scr.bnd-1.0.0-SNAPSHOT.jar You have installed the SCR annotations bnd plugin in Eclipse BndTools, and you can now start using it (see the following Tutorial). Tutorial In this tutorial, we’ll create a "greeting" project, which provides a simple Greeting service with a "sayHello" method, and the implementation will use the Apache Felix SCR annotations: From the File menu, select New -> Bndtools OSGi Project for creating an empty project, and call it "greeting". Then click on bnd.bnd file of the greeting project, then click on Source, and add the following (and then save the file) -buildpath: ${plugin-dir}/org.apache.felix.scr.bnd/org.apache.felix.scr.bnd-1.0.0-SNAPSHOT.jar;version=file -plugin: org.apache.felix.scrplugin.bnd.SCRDescriptorBndPlugin Private-Package: greeting.impl Export-Package: greeting.api Create the greeting.api.Greeting interface: package greeting.api; public interface Greeting { void sayHello(String name); } And create the greeting.impl.GreetingImpl class: package greeting.impl; import greeting.api.Greeting; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Service; @Component(immediate=true) @Service public class GreetingImpl implements Greeting { @Activate private void start() { System.out.println("Starting Greeting Service"); } @Override public void sayHello(String name) { System.out.println("Hello " + name); } } Now, click on bnd.bnd and rebuild the project. you have created your first bndtools project using SCR annotations. Create a Run descriptor (call it "run") with Apache Felix 4 With Gogo Shell. In Run requirement, add the greeting project, as well as Apache Felix SCR from Bnd HUB. Then Run the project: you should see in the console the "Starting Greeting Service" message displayed from the start() method. Plugin Options You can possibly add some optional parameters in the plugin bnd directive (each one separated by a semicolon). For example: -plugin: org.apache.felix.scrplugin.bnd.SCRDescriptorBndPlugin;log=debug;generateAccessors=false Here is the list of options: log + Required: No + Default: warn + The plugin enabled log level. You can select either one of "error", "warn", "info", or "debug". Plugin logs are written in ${java.io.tmpdir}/scrplugin/BSN.log (BSN is the Bundle Symbolic Name of the bundle being analyzed by the plugin). destdir + Required: No + Default: bin + The name of the directory where the descriptor files are generated into. This is also used as the directory where the compiled classes are generated by bndtools. generateAccessors + Required: No + Default: true + If this switch is turned on, the bind and unbind methods for unary references are automatically generated by the plugin. strictMode + Required: No + Default: false + If set to true, a warning will be considered as an error and the build will fail with warnings generated by this task. specVersion + Required: No + Default: — + The plugin will generate a descriptor for the Declarative Service version (e.g. 1.0, 1.1, or 1.2). If no value is specified, the plugin will detect the version and only use 1.1 if features from this version are used. Content licensed under AL2. UI licensed under MPL-2.0 with extensions licensed under AL2