You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Quick Start

This sections presents a simple "Hello World" component defined using annotations, and also explains how to build the bundle using either Bnd or Maven.

Hello World Component

package org.apache.felix.dependencymanager.samples.annotation.hello;

import org.apache.felix.dm.annotation.api.Component;
import org.apache.felix.dm.annotation.api.Start;

@Component
public class HelloWorld {
    @Start
    public void activate() {
       System.out.println("Hello world !");
    }
}

Compiling with Bnd:

The annotations must be processed at compilation phase and you have to use a special Bnd plugin (declared using the "-plugin" bnd directive):

Bundle-Name: Hello World Using Dependency Manager Annotations
Bundle-SymbolicName: org.apache.felix.dependencymanager.samples.annotation.hello
Import-Package: *
Private-Package: org.apache.felix.dependencymanager.samples.annotation.hello
-plugin org.apache.felix.dm.annotation.plugin.bnd.AnnotationPlugin;log=warn

Compiling with Maven:

When compiling with Maven, you have to use the Dependency Manager Maven annotation plugin:

<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<properties>
		<osgi.version>4.2.0</osgi.version>
	</properties>
	<name>Hello World Using Dependency Manager Annotations</name>
	<groupId>org.apache.felix</groupId>
	<artifactId>org.apache.felix.dependencymanager.samples.annotation.hello</artifactId>
	<version>3.0.0-SNAPSHOT</version>
	<packaging>bundle</packaging>
	<dependencies>
		<dependency>
			<groupId>${pom.groupId}</groupId>
			<artifactId>org.apache.felix.dependencymanager.annotation</artifactId>
			<version>3.0.0</version>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>1.5</source>
					<target>1.5</target>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.felix</groupId>
				<artifactId>maven-bundle-plugin</artifactId>
				<version>2.3.4</version>
				<extensions>true</extensions>
				<configuration>
					<instructions>
						<Bundle-Name>Hello World Using Dependency Manager Annotations</Bundle-Name>
						<Bundle-SymbolicName>org.apache.felix.dependencymanager.samples.annotation.hello</Bundle-SymbolicName>
						<Import-Package>*</Import-Package>
						<Private-Package>org.apache.felix.dependencymanager.samples.annotation.hello</Private-Package>
					</instructions>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.felix</groupId>
				<artifactId>org.apache.felix.dependencymanager.annotation</artifactId>
				<version>3.0.0</version>
				<executions>
					<execution>
						<goals>
							<goal>scan</goal>
						</goals>
						<configuration>
							<log>info</log>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>
  • No labels