You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Jérôme Verstrynge <jv...@gmail.com> on 2009/12/29 19:23:02 UTC

Newbie questions about using Bnd with Maven in OSGi

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.

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?

Thanks,

JVersty






---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Newbie questions about using Bnd with Maven in OSGi

Posted by Felix Meschberger <fm...@gmail.com>.
Hi,

On 29.12.2009 20:13, Jérôme Verstrynge wrote:
> Thanks Felix. I just have a confirmation question (see below).
> 
> Felix Meschberger wrote:
>> 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.
>>   
> According to what you say (and if I understand you correctly),
> specifying MyServiceActivator is not necessary, because there can only
> be one in activator in the .jar and by default bnd will select it to
> populate the MANIFEST, correct?

Yes and no ;-)

Yes, there may only be one activator but IIRC neither the
maven-bundle-plugin nor BND automagically set the Bundle-Activator
header. You have to set it in your instructions as indicated above. The
actual value must of course be the fully qualified name of the activator
class.

Regards
Felix

>> 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.
>>   
> Just took a look at it, it looks great. Thanks for the pointer !!!
> 
> JVerstry
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Newbie questions about using Bnd with Maven in OSGi

Posted by Jérôme Verstrynge <jv...@gmail.com>.
Thanks Felix. I just have a confirmation question (see below).

Felix Meschberger wrote:
> 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.
>   
According to what you say (and if I understand you correctly), 
specifying MyServiceActivator is not necessary, because there can only 
be one in activator in the .jar and by default bnd will select it to 
populate the MANIFEST, correct?
> 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.
>   
Just took a look at it, it looks great. Thanks for the pointer !!!

JVerstry

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Newbie questions about using Bnd with Maven in OSGi

Posted by Felix Meschberger <fm...@gmail.com>.
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: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org