You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by "Lewis, Eric" <Er...@ipi.ch> on 2008/12/12 10:31:49 UTC

Newbie question regarding dependencies

Hi

I'm one of the persons responsible for the build in our company.
Frankly, I don't have a clue about OSGI, because I'm on the server side
of things (and we use JEE).
However, the idea is that the server part offers some APIs; every API
resides in a Maven project, whose artifact can be used by some other
plain Java class or by Eclipse (we use RCP for our client).

So, after a client team member showed me that an OSGI bundle just
differs by the content of its MANIFEST.MF, I looked around and found
your excellent Felix plugin.

However, I see a problem which I can't resolve with my limited
knowledge.

Let's say my API uses other libraries, like Commons Lang. The default
way that Felix offers is to include all Maven dependencies as JARs in
the bundle JAR. This works, but I don't see the point in having the same
JAR over and over again in separate bundles. Maybe someone can explain
this to me.

So, we're looking for an alternative, which is to have the Maven
dependencies point to the OSGI bundles which SpringSource offers.

For instance:
  <dependencies>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>com.springsource.org.apache.commons.lang</artifactId>
      <version>2.4.0</version>
    </dependency>
  </dependencies>


The idea is that all these bundles are then downloaded to some place and
that (in my example) the API just uses the Require-Bundle to state its
dependencies. However, I have no idea how to do this with the Felix
plugin. Is it possible at all? Does it make sense at all?

As I said, I'm new to all of this, and maybe my ideas are completely
weird  :-)

But any help is greatly appreciated!

Best regards,
Eric

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


AW: AW: Newbie question regarding dependencies

Posted by "Lewis, Eric" <Er...@ipi.ch>.
Hi Felix 

> 
> Let's see: Obvisouly you only pack a single package (the exported
> ch.ipi.earexample.api) into the bundle. The maven bundle 
> plugin analyzes
> these classes and calculates the dependencies, which seem to just be
> javax.ejb (except re-importing the exported classes).
> 
> So you are API package does not have a dependency on the Commons Lang
> package and hence there is no Import-Package entry for it.

Ok, now I understand! I added the Commons Lang dependency only in the
POM as an example, but didn't really use it in my interface. Now I've
added another method which uses the ToStringBuilder, and I get

Manifest-Version: 1.0
Export-Package: ch.ipi.earexample.api;uses:="javax.ejb,org.apache.comm
 ons.lang.builder"
Built-By: lewis_lee
Tool: Bnd-0.0.255
Bundle-Name: ear-example-api
Created-By: Apache Maven Bundle Plugin
Bundle-Vendor: Swiss Federal Institute of Intellectual Property
Build-Jdk: 1.6.0_07
Bundle-Version: 1.0.0.SNAPSHOT
Bnd-LastModified: 1229096385549
Bundle-ManifestVersion: 2
Bundle-Activator: ch.ipi.earexample.api.Activator
Bundle-Description: A simple EAR
Bundle-DocURL: http://www.ipi.ch
Bundle-SymbolicName: ch.ipi.ear-example-api
Import-Package: ch.ipi.earexample.api,javax.ejb,org.apache.commons.lan
 g.builder;version="2.4"


Smart!
So effectively, only the packages which are really used are shown as
bundle dependencies, right?


> > Also, what is the strategy concerning the dependency 
> bundles? My idea
> > was that the server API defines its dependencies as OSGI 
> bundles. But if
> > they aren't included in the created JAR and the OSGI platform has to
> > figure out where to get those packages, they have to be present as
> > bundles in some known directory, right?
> 
> As I understand the API itself does not need nor use the commons lang
> library. It is some implementation of that API making use of this
> library. Therefore that implementation will have to declare the
> dependency. And this is good, because the use of the commons lang
> library seems to be an implementation detail unrelated to the 
> actual API.

Well, as I said, it was only a bogus dependency. Things are now clearer.

> Now, if your implementation uses the common lang library, the
> implementation will either include that library (as per 
> Embed-Dependency
> for example) or import it with Import-Package (generated by the maven
> bundle plugin automatically). What you effectively do, depends on your
> requirement and the circumstances.
>
> For example, in the case of a library such as commons lang or commons
> collections, I would use the import apporach and deploy the 
> libraries as
> separate bundles into the framework. In the case of for 
> example JDOM, I
> would probably rather embed it and use it from within.

Since we want all external dependencies to exist only once, we'll use
Import-Package and have the bundles containing e.g. Commons Lang ready
at runtime.


> > We're building an RCP client, and for various reasons, we 
> just call the
> > usual PDE build from Maven. To have at least a bit of dependency
> > management, my idea was to have just one POM for the whole 
> client (with
> > all features, plugins etc. below, but not touched by Maven) 
> where all
> > those dependencies are referenced as bundles. However, this 
> would mean
> > that they're defined both in the API and somewhere in the 
> client, which
> > is not very nice  :-)  Is my idea wrong or is there an easier way to
> > handle this?
> 
> Hmm, I do not quite understand, what you need mavens dependency
> management for, then. Since you then seem to declare the 
> dependencies in
> two places (and trying to sync is an endless job), the 
> MANIFEST through
> PDE functionality and the maven POM.
> 
> In addition, maven does not reference dependencies as bundles, this
> confuses me bit ;-)
> 
> Finally, I do not understand, why listing dependencies in a POM, which
> is used to call the PDE build, has an influence on an dependencies of
> the API.

Well, perhaps my ideas a weird ;-)  but I figured that since my client
needs my API and my API needs Commons Lang and since the Commons Lang
bundle is the same as the normal Commons Lang JAR with some OSGI
information, I might as well use the bundle in the API (they are
available from the SpringSource Maven repository anyway). Otherwise my
API would use the normal Commons Lang (downloaded by Maven into our
repository) and by the Import-Package the client would be forced to use
the Commons Lang bundle (also downloaded by whoever), making the same
thing (Commons Lang) exist in two files and in two places.

As for the normal PDE build: The plugins declare their dependencies, and
(if I'm not mistaken) the map file declares where to get them. Since we
from the build team want to have some control about what libraries are
used, we define that any library which exists in our Master (Parent) POM
can be used, and this goes for the client as well.
So yes, the client developers would have to define a new library in the
client POM, then it's downloaded by Maven and copied (or whatever) for
the PDE build and for the Eclipse plugin projects to use.

Best regards,
Eric

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


Re: AW: Newbie question regarding dependencies

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

Lewis, Eric schrieb:
> Hi Felix
> 
> First of all, thanks for your reply!
> 
>>> Let's say my API uses other libraries, like Commons Lang. 
>> The default
>>> way that Felix offers is to include all Maven dependencies 
>> as JARs in
>>> the bundle JAR. This works, but I don't see the point in 
>> having the same
>>> JAR over and over again in separate bundles. Maybe someone 
>> can explain
>>> this to me.
>> This is AFACT not the default. The default is defined Import-Package
>> statements for the dependent library packages. These imports will then
>> have to be resolved by appropriate exports in the OSGi framework.
> 
> Yes, sorry, I forgot to mention my plugin configuration, which includes
>    <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
>    <Embed-Transitive>true</Embed-Transitive>
> 
> But for the following results, this is no longer part of the
> configuration.

ok.

> 
>> So for example if you deploy a bundleized Commons Lang 
>> library (IIRC the
>> Apache Commons project will release new versions with 
>> appropriate bundle
>> headers out of the box), that bundle will export the lang packages,
>> which will be used by your bundle.
>>
>> You may of course decide to include your dependencies (or 
>> some of them)
>> into your bundle and not import it from the framework. This depends a
>> bit on the use case. But in the case of your API bundle, it 
>> is probably
>> more appropriate to just Import-Package the dependencies.
>>
>>
>> You should not use Require-Bundle. See [1] for an excellent 
>> description,
>> why. Rather let the maven-bundle-plugin generate the required
>> Import-Package headers for you and let the OSGi framework resolve the
>> dependencies.
>>
>> Hope this helps.
>>
>> Regards
>> Felix
>>
>> [1] http://www.aqute.biz/Blog/2006-04-29
> 
> Well, this is my POM (excerpt):
> 
>   <dependencies>
>     <dependency>
>       <groupId>org.apache.commons</groupId>
>       <artifactId>com.springsource.org.apache.commons.lang</artifactId>
>       <version>2.4.0</version>
>     </dependency>
>   </dependencies>
> 
>   <build>
>     <plugins>
>       <plugin>
>         <groupId>org.apache.felix</groupId>
>         <artifactId>maven-bundle-plugin</artifactId>
>         <extensions>true</extensions>
>         <configuration>
>           <instructions>
>             <Export-Package>ch.ipi.earexample.api</Export-Package>
>             <Private-Package></Private-Package>
>  
> <Bundle-Activator>ch.ipi.earexample.api.Activator</Bundle-Activator>
>           </instructions>
>         </configuration>
>       </plugin>
>     </plugins>
>   </build>
> 
> Now, if I understand you correctly, the 'MANIFEST.MF' should
> automatically contain 'Import-Package' information for the Commons Lang
> packages?
> Well, running 'mvn package' gives me this:
> 
> Manifest-Version: 1.0
> Export-Package: ch.ipi.earexample.api;uses:="javax.ejb"
> Built-By: lewis_lee
> Tool: Bnd-0.0.255
> Bundle-Name: ear-example-api
> Created-By: Apache Maven Bundle Plugin
> Bundle-Vendor: Swiss Federal Institute of Intellectual Property
> Build-Jdk: 1.6.0_07
> Bundle-Version: 1.0.0.SNAPSHOT
> Bnd-LastModified: 1229082128327
> Bundle-ManifestVersion: 2
> Bundle-Activator: ch.ipi.earexample.api.Activator
> Bundle-Description: A simple EAR
> Bundle-DocURL: http://www.ipi.ch
> Bundle-SymbolicName: ch.ipi.ear-example-api
> Import-Package: ch.ipi.earexample.api,javax.ejb
> 
> I don't see any Commons Lang packages. Do I have to configure
> <Import-Package> separately?

Let's see: Obvisouly you only pack a single package (the exported
ch.ipi.earexample.api) into the bundle. The maven bundle plugin analyzes
these classes and calculates the dependencies, which seem to just be
javax.ejb (except re-importing the exported classes).

So you are API package does not have a dependency on the Commons Lang
package and hence there is no Import-Package entry for it.

> 
> 
> Also, what is the strategy concerning the dependency bundles? My idea
> was that the server API defines its dependencies as OSGI bundles. But if
> they aren't included in the created JAR and the OSGI platform has to
> figure out where to get those packages, they have to be present as
> bundles in some known directory, right?

As I understand the API itself does not need nor use the commons lang
library. It is some implementation of that API making use of this
library. Therefore that implementation will have to declare the
dependency. And this is good, because the use of the commons lang
library seems to be an implementation detail unrelated to the actual API.

Now, if your implementation uses the common lang library, the
implementation will either include that library (as per Embed-Dependency
for example) or import it with Import-Package (generated by the maven
bundle plugin automatically). What you effectively do, depends on your
requirement and the circumstances.

For example, in the case of a library such as commons lang or commons
collections, I would use the import apporach and deploy the libraries as
separate bundles into the framework. In the case of for example JDOM, I
would probably rather embed it and use it from within.

> 
> We're building an RCP client, and for various reasons, we just call the
> usual PDE build from Maven. To have at least a bit of dependency
> management, my idea was to have just one POM for the whole client (with
> all features, plugins etc. below, but not touched by Maven) where all
> those dependencies are referenced as bundles. However, this would mean
> that they're defined both in the API and somewhere in the client, which
> is not very nice  :-)  Is my idea wrong or is there an easier way to
> handle this?

Hmm, I do not quite understand, what you need mavens dependency
management for, then. Since you then seem to declare the dependencies in
two places (and trying to sync is an endless job), the MANIFEST through
PDE functionality and the maven POM.

In addition, maven does not reference dependencies as bundles, this
confuses me bit ;-)

Finally, I do not understand, why listing dependencies in a POM, which
is used to call the PDE build, has an influence on an dependencies of
the API.

Hope this helps.

Regards
Felix

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


AW: Newbie question regarding dependencies

Posted by "Lewis, Eric" <Er...@ipi.ch>.
Hi Felix

First of all, thanks for your reply!

> > Let's say my API uses other libraries, like Commons Lang. 
> The default
> > way that Felix offers is to include all Maven dependencies 
> as JARs in
> > the bundle JAR. This works, but I don't see the point in 
> having the same
> > JAR over and over again in separate bundles. Maybe someone 
> can explain
> > this to me.
> 
> This is AFACT not the default. The default is defined Import-Package
> statements for the dependent library packages. These imports will then
> have to be resolved by appropriate exports in the OSGi framework.

Yes, sorry, I forgot to mention my plugin configuration, which includes
   <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
   <Embed-Transitive>true</Embed-Transitive>

But for the following results, this is no longer part of the
configuration.

> 
> So for example if you deploy a bundleized Commons Lang 
> library (IIRC the
> Apache Commons project will release new versions with 
> appropriate bundle
> headers out of the box), that bundle will export the lang packages,
> which will be used by your bundle.
> 
> You may of course decide to include your dependencies (or 
> some of them)
> into your bundle and not import it from the framework. This depends a
> bit on the use case. But in the case of your API bundle, it 
> is probably
> more appropriate to just Import-Package the dependencies.
> 
> 
> You should not use Require-Bundle. See [1] for an excellent 
> description,
> why. Rather let the maven-bundle-plugin generate the required
> Import-Package headers for you and let the OSGi framework resolve the
> dependencies.
> 
> Hope this helps.
> 
> Regards
> Felix
> 
> [1] http://www.aqute.biz/Blog/2006-04-29

Well, this is my POM (excerpt):

  <dependencies>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>com.springsource.org.apache.commons.lang</artifactId>
      <version>2.4.0</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <instructions>
            <Export-Package>ch.ipi.earexample.api</Export-Package>
            <Private-Package></Private-Package>
 
<Bundle-Activator>ch.ipi.earexample.api.Activator</Bundle-Activator>
          </instructions>
        </configuration>
      </plugin>
    </plugins>
  </build>

Now, if I understand you correctly, the 'MANIFEST.MF' should
automatically contain 'Import-Package' information for the Commons Lang
packages?
Well, running 'mvn package' gives me this:

Manifest-Version: 1.0
Export-Package: ch.ipi.earexample.api;uses:="javax.ejb"
Built-By: lewis_lee
Tool: Bnd-0.0.255
Bundle-Name: ear-example-api
Created-By: Apache Maven Bundle Plugin
Bundle-Vendor: Swiss Federal Institute of Intellectual Property
Build-Jdk: 1.6.0_07
Bundle-Version: 1.0.0.SNAPSHOT
Bnd-LastModified: 1229082128327
Bundle-ManifestVersion: 2
Bundle-Activator: ch.ipi.earexample.api.Activator
Bundle-Description: A simple EAR
Bundle-DocURL: http://www.ipi.ch
Bundle-SymbolicName: ch.ipi.ear-example-api
Import-Package: ch.ipi.earexample.api,javax.ejb

I don't see any Commons Lang packages. Do I have to configure
<Import-Package> separately?


Also, what is the strategy concerning the dependency bundles? My idea
was that the server API defines its dependencies as OSGI bundles. But if
they aren't included in the created JAR and the OSGI platform has to
figure out where to get those packages, they have to be present as
bundles in some known directory, right?

We're building an RCP client, and for various reasons, we just call the
usual PDE build from Maven. To have at least a bit of dependency
management, my idea was to have just one POM for the whole client (with
all features, plugins etc. below, but not touched by Maven) where all
those dependencies are referenced as bundles. However, this would mean
that they're defined both in the API and somewhere in the client, which
is not very nice  :-)  Is my idea wrong or is there an easier way to
handle this?

Best regards,
Eric

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


Re: Newbie question regarding dependencies

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

Lewis, Eric schrieb:
> Hi
> 
> I'm one of the persons responsible for the build in our company.
> Frankly, I don't have a clue about OSGI, because I'm on the server side
> of things (and we use JEE).

Just as a side note: OSGi is not restricted to the client side. In fact
with Apache Sling we are very successfully using OSGi on the server side.

> However, the idea is that the server part offers some APIs; every API
> resides in a Maven project, whose artifact can be used by some other
> plain Java class or by Eclipse (we use RCP for our client).
> 
> So, after a client team member showed me that an OSGI bundle just
> differs by the content of its MANIFEST.MF, I looked around and found
> your excellent Felix plugin.
> 
> However, I see a problem which I can't resolve with my limited
> knowledge.
> 
> Let's say my API uses other libraries, like Commons Lang. The default
> way that Felix offers is to include all Maven dependencies as JARs in
> the bundle JAR. This works, but I don't see the point in having the same
> JAR over and over again in separate bundles. Maybe someone can explain
> this to me.

This is AFACT not the default. The default is defined Import-Package
statements for the dependent library packages. These imports will then
have to be resolved by appropriate exports in the OSGi framework.

So for example if you deploy a bundleized Commons Lang library (IIRC the
Apache Commons project will release new versions with appropriate bundle
headers out of the box), that bundle will export the lang packages,
which will be used by your bundle.

You may of course decide to include your dependencies (or some of them)
into your bundle and not import it from the framework. This depends a
bit on the use case. But in the case of your API bundle, it is probably
more appropriate to just Import-Package the dependencies.

> 
> So, we're looking for an alternative, which is to have the Maven
> dependencies point to the OSGI bundles which SpringSource offers.
> 
> For instance:
>   <dependencies>
>     <dependency>
>       <groupId>org.apache.commons</groupId>
>       <artifactId>com.springsource.org.apache.commons.lang</artifactId>
>       <version>2.4.0</version>
>     </dependency>
>   </dependencies>
> 
> 
> The idea is that all these bundles are then downloaded to some place and
> that (in my example) the API just uses the Require-Bundle to state its
> dependencies. However, I have no idea how to do this with the Felix
> plugin. Is it possible at all? Does it make sense at all?

You should not use Require-Bundle. See [1] for an excellent description,
why. Rather let the maven-bundle-plugin generate the required
Import-Package headers for you and let the OSGi framework resolve the
dependencies.

Hope this helps.

Regards
Felix

[1] http://www.aqute.biz/Blog/2006-04-29

> 
> As I said, I'm new to all of this, and maybe my ideas are completely
> weird  :-)
> 
> But any help is greatly appreciated!
> 
> Best regards,
> Eric
> 
> ---------------------------------------------------------------------
> 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