Return-Path: X-Original-To: apmail-felix-commits-archive@www.apache.org Delivered-To: apmail-felix-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id ACE8D1093A for ; Fri, 13 Sep 2013 16:11:57 +0000 (UTC) Received: (qmail 92297 invoked by uid 500); 13 Sep 2013 16:00:57 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 92266 invoked by uid 500); 13 Sep 2013 16:00:57 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 92214 invoked by uid 99); 13 Sep 2013 16:00:57 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Sep 2013 16:00:57 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Sep 2013 16:00:55 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2E0D52388B34; Fri, 13 Sep 2013 16:00:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1522989 - /felix/site/trunk/content/documentation/subprojects/apache-felix-maven-scr-plugin/apache-felix-scr-bndtools-use.mdtext Date: Fri, 13 Sep 2013 16:00:35 -0000 To: commits@felix.apache.org From: pderop@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130913160035.2E0D52388B34@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: pderop Date: Fri Sep 13 16:00:34 2013 New Revision: 1522989 URL: http://svn.apache.org/r1522989 Log: Initial version for SCR annotations bnd plugin tutorial Modified: felix/site/trunk/content/documentation/subprojects/apache-felix-maven-scr-plugin/apache-felix-scr-bndtools-use.mdtext Modified: felix/site/trunk/content/documentation/subprojects/apache-felix-maven-scr-plugin/apache-felix-scr-bndtools-use.mdtext URL: http://svn.apache.org/viewvc/felix/site/trunk/content/documentation/subprojects/apache-felix-maven-scr-plugin/apache-felix-scr-bndtools-use.mdtext?rev=1522989&r1=1522988&r2=1522989&view=diff ============================================================================== --- felix/site/trunk/content/documentation/subprojects/apache-felix-maven-scr-plugin/apache-felix-scr-bndtools-use.mdtext (original) +++ felix/site/trunk/content/documentation/subprojects/apache-felix-maven-scr-plugin/apache-felix-scr-bndtools-use.mdtext Fri Sep 13 16:00:34 2013 @@ -1,4 +1,97 @@ Title: Apache Felix SCR Annotations BndTools Use Excerpt: Using the Apache Felix SCR Annotations Bnd plugin to generate Declarative Services and Metatype Service descriptors in BndTools. -Page under construction. +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 makes it easy +to demonstrate the use of Apache SCR annotations within BndTools. + +If you are not yet familiar with BndTools or if you don't have already installed it, you can take a look at [BndTools homepage](http://bndtools.org/). + +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: + + :::sh + $ 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: + +* 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". +* 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: + + :::java + package greeting.api; + + public interface Greeting { + void sayHello(String name); + } + +* Create the greeting.impl.GreetingImpl class: + + :::java + 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.