Hi,

On 29.12.2009 19:23, Jérôme Verstrynge wrote:
> Hi,
> 
> I am new to OSGi and I am trying to add OSGi metadata to a .jar using
> Maven. I have seen the 'Adding OSGi metadata to existing projects
> without changing the packaging type' section
> at
> http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html,
> that is:
> 
> <plugin>
>  <artifactId>maven-jar-plugin</artifactId>
>  <configuration>
>    <archive>      
> <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
> 
>    </archive>  </configuration>
> </plugin>  <plugin>    <groupId>org.apache.felix</groupId>
>  <artifactId>maven-bundle-plugin</artifactId>
>  <executions>
>    <execution>
>      <id>bundle-manifest</id>
>      <phase>process-classes</phase>
>      <goals>           <goal>manifest</goal>
>      </goals>      </execution>
>  </executions>
> </plugin>
> 
> My .jar contains a MyAPIService public abstract class, and a
> MyServiceImpl class implementing MyAPIService. It also contains a
> MyServiceActivator extending org.osgi.framework.BundleActivator.
> 
> I have two questions:
> 
> i) The documentation does not mention configuration of the maven plugin
> to specify what my activator is, or what should be exported, imported,
> etc... Is this a necessary step in my case? If yes, how should I
> proceed? My service does not have dependencies on other services.

The maven-bundle-plugin has very good defaults (which are explained on
the apache-felix-maven-bundle-plugin-bnd.html page). If you want to
tweak these defaults add a <configuration> element containing an
<instruction> element which may take child elements being used as BND
instructions.

E.g.

   <configuration>
      <instructions>
         <Bundle-Activator>
            MyServiceActivator>
         </Bundle-Activator>
      </instructions>
   </configuration>

defines the bundle activator manifest header.

Most Maven projects in Apache Felix have bundle plugin configuration and
looking at these for hints in paralell to reading the
maven-bundle-plugin page is probably a good idea.

> 
> ii) My situation is simple, but what if I have two activators for two
> services in the same .jar? Will the plugins mentioned above
> automatically detect this and populate the MANIFEST properly? Is this
> good practice to put two (or more) services in the same .jar? Should I
> separate them?

You may place as many service classes in the bundle as you see fit. But
you may only have a single bundle activator (this is defined in the OSGi
core spec) configured with the Bundle-Activator manifest header.

The activator may create and register as many services as are needed.

You may also use component technology such as Declarative Services or
(Apache Felix) iPojo, which take away many of the day-to-day task for
setting up services.

Regards
Felix


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to