-1

How create a bundle using Apache karaf 3? Someone know ?

I have try in Eclipse:
I export a jar with a manifest file ... and why I have this error:

karaf@root(dev)> feature:repo-add file:///C:/Users/xx/Downloads/apache-kara
f-3.0.1/apache-karaf-3.0.1/deploy/features.xml
Adding feature url file:///C:/Users/xx/Downloads/apache-karaf-3.0.1/apache-
karaf-3.0.1/deploy/features.xml
karaf@root(dev)> feature:install greeter_server
Error executing command: Jar is not a bundle, no Bundle-SymbolicName file:///C:/
Users/xx/Downloads/apache-karaf-3.0.1/apache-karaf-3.0.1/deploy/nebula_cdat
etime_VF4.jar
karaf@root(dev)>

This is my features.xml:

<features>
<feature name='greeter_server' version='1.0'>
<bundle>file:///C:/Users/xx/Downloads/apache-karaf-3.0.1/apache-karaf-3.0.1/deploy/nebula_cdatetime_VF4.jar</bundle>
</feature>
</features>  
Prophet
  • 32,350
  • 22
  • 54
  • 79
user3623242
  • 21
  • 1
  • 4
  • Which tutorials or documentation did you read before starting? – Neil Bartlett Jun 01 '14 at 13:42
  • I have done this tutorial : http://www.vogella.com/tutorials/OSGi/article.html and this tutorial : http://www.eclipsetotale.com/articles/Developpement_de_plugins_Eclipse_partie1.html Thank you for your answer. – user3623242 Jun 01 '14 at 15:11
  • Please re-read section 2 of Lars' tutorial. It details how bundles differ from plain JARs. – Neil Bartlett Jun 01 '14 at 17:28
  • Looks like you haven't made any efforts to trouble shoot the issue. Anyone remotely familiar with OSGi knows they need to assign a value to Bundle-SymbolicName attribute in the jar manifest file. Your jar manifest file is probably doesn't have it declared. It may help to make your build tool whether ant/maven/gradle generate the manifest of your jar. – The Governor Jun 17 '14 at 21:22

2 Answers2

1

When you want to export a bundle or a declarative service from eclipse rcp you must use the file -> export -> plugin development-> deployable plugins and fragments as explained here.

Obviously the project you want to export as a bundle must have a sound manifest file. To have an idea of a correct osgi-friendly structure your project should have, you could create a test plugin project in eclipse rcp using the File → New → Other... → Plug-in Development → Plug-in Project menu. In the wizard you can choose to create a simple osgi bundle with an activator. The outcome is a skeleton for your new osgi bundle.

matteo rulli
  • 1,443
  • 2
  • 18
  • 30
0

I think an easier and cleaner way is to use Maven. This way you can produce a correct OSGI ready JAR which may be loaded quickly into Karaf. In this case pom.xml file should be like this:

<project xmlns="http://maven.apache.org/POM/4.0.0">
  <modelVersion>4.0.0</modelVersion>
  <groupId>your.group
  <artifactId>artifact-123</artifactId>
  <name>Karaf OSGI Module</name>
  <packaging>bundle</packaging>
  ....
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>2.4.0</version>
        <extensions>true</extensions>
        <configuration>
          <instructions />
        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>

This kind of POM file will produce a JAR which is OSGI compatible and you don't have to mess up with absolute file names. In your feature.xml we can declare the module like this:

<bundle>mvn:your.group/artifact-123/${pom.version}</bundle>
stefan.itu
  • 41
  • 5