blob: e3fd1a41986c90a29fa8a65d8e8e862c4330827b [file] [log] [blame]
h1. Add extended information to bundles
Karaf supports a OSGI-INF/bundle.info file in a bundle.
This file is extended description of the bundle. It supports ASCII character declarations (for adding color, formatting, etc).
For instance, you can define a bundle like this (using Apache Felix maven-bundle-plugin):
{code:lang=xml}
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.groupId</groupId>
<artifactId>my.bundle</artifactId>
<version>1.0-SNAPSHOT</version>
<name>My Bundle</name>
<description>My bundle short description</description>
<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.2.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
...
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
{code}
And simply add a src/main/resources/OSGI-INF/bundle.info file containing, for instance:
{code}
\u001B[1mSYNOPSIS\u001B[0m
${project.description}
\u001B[1mDESCRIPTION\u001B[0m
Long description of your bundle, including usage, etc.
\u001B[1mSEE ALSO\u001B[0m
\u001B[36mhttp://yourside\u001B[0m
\u001B[36mhttp://yourside/docs\u001B[0m
{code}
You can display this extended information using:
{code}
root@karaf> osgi:info
{code}
h1. Creating bundles for third party dependencies
Karaf supports the wrap: protocol execution.
It allows for directly deploying third party dependencies, like Apache Commons Lang:
{code}
root@karaf> osgi:install wrap:mvn:commons-lang/commons-lang/2.4
{code}
You can specify OSGi statements in the wrap URL:
from the shell
{code}
root@karaf> osgi:install -s 'wrap:mvn:commons-lang/commons-lang/2.4$Bundle-SymbolicName=commons-lang&Bundle-Version=2.4'
{code}
from features.xml
{code}
<bundle>wrap:mvn:commons-lang/commons-lang/2.4$Bundle-SymbolicName=commons-lang&amp;Bundle-Version=2.4</bundle>
{code}
You can also create a wrap bundle for a third party dependency.
This bundle is simply a Maven POM that shades an existing jar and package into a jar bundle.
For instance, to create an OSGi bundle that wraps Apache Commons Lang, you can simply define the following Maven POM:
{code:lang=xml}
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>osgi.commons-lang</groupId>
<artifactId>osgi.commons-lang</artifactId>
<version>2.4</version>
<packaging>bundle</packaging>
<name>commons-lang OSGi Bundle</name>
<description>This OSGi bundle simply wraps commons-lang-2.4.jar artifact.</description>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>commons-lang:commons-lang</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>commons-lang:commons-lang</artifact>
<excludes>
<exclude>**</exclude>
</excludes>
</filter>
</filters>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<createDependencyReducedPom>true</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.1.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Export-Package>*</Export-Package>
<Import-Package></Import-Package>
<_versionpolicy>[$(version;==;$(@)),$(version;+;$(@)))</_versionpolicy>
<_removeheaders>Ignore-Package,Include-Resource,Private-Package,Embed-Dependency</_removeheaders>
</instructions>
<unpackBundle>true</unpackBundle>
</configuration>
</plugin>
</build>
</project>
{code}
You have now a OSGi bundle for commons-lang that you can deploy directly:
{code}
root@karaf> osgi:install -s mvn:osgi.commons-lang/osgi.commons-lang/2.4
{code}
Some more information is available at [http://gnodet.blogspot.com/2008/09/id-like-to-talk-bit-about-third-party.html], [http://blog.springsource.com/2008/02/18/creating-osgi-bundles/] and [http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html].