You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by GERODOLLE Anne RD-MAPS-GRE <an...@orange-ftgroup.com> on 2007/12/21 12:53:49 UTC

Classes duplicated when using Embed-dependency

Hi everybody,
 
I have noticed that when using Embed-Dependency, if it occurs that one of the packages in the embedded library is either exported or declared as private, classes of this package are also put in the jar, so that they are present twice in the bundle classpath (once in the embedded jar, and once directly in the bundle)..
 
Is that possible to avoid this, if so how ?
 
As an illustration, I'm including a pom.xml that builds a bundle embedding log4j (this is derivated from the felix log4j bundle).
 
Thanks in advance,
 
Anne
 
 

Anne Gérodolle
FT/RD/MAPS/AMS/SUME

architecture de systèmes répartis

distributed system architecture
+33 4 76 76 41 78
anne.gerodolle@orange-ftgroup.com

 

 
 

RE: Classes duplicated when using Embed-dependency

Posted by GERODOLLE Anne RD-MAPS-GRE <an...@orange-ftgroup.com>.
Thanks Stuart,

I've just tested on my real bundle -replaced Export-Package with _exportcontents, and it worked.

Best regards,

Anne

-----Message d'origine-----
De : mcculls@gmail.com [mailto:mcculls@gmail.com] De la part de Stuart McCulloch
Envoyé : vendredi 21 décembre 2007 14:38
À : users@felix.apache.org
Objet : Re: Classes duplicated when using Embed-dependency

On 21/12/2007, Stuart McCulloch <st...@jayway.net> wrote:
>
> On 21/12/2007, GERODOLLE Anne RD-MAPS-GRE < 
> anne.gerodolle@orange-ftgroup.com> wrote:
> >
> >  Hi everybody,
> >
> > I have noticed that when using Embed-Dependency, if it occurs that 
> > one of the packages in the embedded library is either exported or 
> > declared as private, classes of this package are also put in the 
> > jar, so that they are present twice in the bundle classpath (once in 
> > the embedded jar, and once directly in the bundle)..
> >
>
> this is primarily because the BND tool is generic, and doesn't know 
> about Maven dependencies...
>
> therefore to support embedding of dependencies the bundleplugin 
> translates the Embed-Dependency instruction and the list of 
> dependencies provided by Maven into Include-Resource and 
> Bundle-ClassPath equivalents
>
> now, because BND uses Include-Resource, Export-Package and 
> Private-Package to decide the contents of the bundle, if you ask it to 
> embed a jar and then ask it to pull some classes into the bundle you 
> may of course find some duplication if the same classes are also in 
> the embedded jar
>
> Is that possible to avoid this, if so how ?
> >
>
> yes - but rather than adding complex code to detect such duplication 
> (which would get very messy) the solution involves using a different 
> BND instruction (called
> -exportcontents) which lets you set the exported packages without 
> affecting the bundle contents
>

just realized this option is missing from the online bundleplugin docs - will add it later today :)

for example, to wrap Log4J you'd embed the dependency and use exportcontents
> to expose the API:
>
>   <configuration>
>     <instructions>
>       <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
>       <_exportcontents>org.apache.log4j</_exportcontents>
>       <Import-Package>
>                 !javax.mail,
>                 !javax.management,
>                 !javax.jms,
>                 !javax.*,
>                 !com.sun.jdmk.comm,
>                 *
>       </Import-Package>
>       <Embed-Dependency>*</Embed-Dependency>
>     </instructions>
>   </configuration>
>
> there's no need to set Private-Package because the jar is already 
> embedded
> - btw, you
> can use <Embed-Dependency>*;inline=true</Embed-Dependency> to inline 
> the jar
>
> Note that in XML we use <_exportcontents> due to rules on valid tag 
> names, in a BND properties file we would use -exportcontents ( see 
> http://aqute.biz/Code/Bnd#directives
> )
>
> couple of follow-up points:
>
> 1) if you want a good logging service for OSGi, try Pax-Logging which 
> is on it's second RC:
>
>
> http://wiki.ops4j.org/confluence/display/ops4j/2007/12/19/Pax-Logging+
> 1.0+RC2
>
>   it provides the Log4J API and many others and logging can be 
> configured through OSGi
>
> 2) you can quickly create wrapper poms for third party libraries using
> pax-wrap-jar:
>
>       http://www.ops4j.org/projects/pax/construct/help/wrap-jar.html
>
>    which is part of the Pax-Construct tools (also provides bundle + 
> bean
> archetypes)
>
> HTH
>
> As an illustration, I'm including a pom.xml that builds a bundle 
> embedding
> > log4j (this is derivated from the felix log4j bundle).
> >
> > Thanks in advance,
> >
> > Anne
> >
> > * *
> >
> > * *
> >
> > *Anne Gérodolle
> > FT/RD/MAPS/AMS/SUME*
> >
> > *architecture de systèmes répartis*
> >
> > *distributed system architecture
> > +33 4 76 76 41 78
> > anne.gerodolle@orange-ftgroup.com*
> >
> > * *
> >
> >
> >
> > --------------------------------------------------------------------
> > - To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> > For additional commands, e-mail: users-help@felix.apache.org
> >
> >
>
>
> --
> Cheers, Stuart
>



--
Cheers, Stuart

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


Re: Classes duplicated when using Embed-dependency

Posted by Stuart McCulloch <st...@jayway.net>.
On 21/12/2007, Stuart McCulloch <st...@jayway.net> wrote:
>
> On 21/12/2007, GERODOLLE Anne RD-MAPS-GRE <
> anne.gerodolle@orange-ftgroup.com> wrote:
> >
> >  Hi everybody,
> >
> > I have noticed that when using Embed-Dependency, if it occurs that one
> > of the packages in the embedded library is either exported or declared as
> > private, classes of this package are also put in the jar, so that they are
> > present twice in the bundle classpath (once in the embedded jar, and once
> > directly in the bundle)..
> >
>
> this is primarily because the BND tool is generic, and doesn't know about
> Maven dependencies...
>
> therefore to support embedding of dependencies the bundleplugin translates
> the Embed-Dependency
> instruction and the list of dependencies provided by Maven into
> Include-Resource and Bundle-ClassPath
> equivalents
>
> now, because BND uses Include-Resource, Export-Package and Private-Package
> to decide the contents
> of the bundle, if you ask it to embed a jar and then ask it to pull some
> classes into the bundle you may
> of course find some duplication if the same classes are also in the
> embedded jar
>
> Is that possible to avoid this, if so how ?
> >
>
> yes - but rather than adding complex code to detect such duplication
> (which would get very messy)
> the solution involves using a different BND instruction (called
> -exportcontents) which lets you set the
> exported packages without affecting the bundle contents
>

just realized this option is missing from the online bundleplugin docs -
will add it later today :)

for example, to wrap Log4J you'd embed the dependency and use exportcontents
> to expose the API:
>
>   <configuration>
>     <instructions>
>       <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
>       <_exportcontents>org.apache.log4j</_exportcontents>
>       <Import-Package>
>                 !javax.mail,
>                 !javax.management,
>                 !javax.jms,
>                 !javax.*,
>                 !com.sun.jdmk.comm,
>                 *
>       </Import-Package>
>       <Embed-Dependency>*</Embed-Dependency>
>     </instructions>
>   </configuration>
>
> there's no need to set Private-Package because the jar is already embedded
> - btw, you
> can use <Embed-Dependency>*;inline=true</Embed-Dependency> to inline the
> jar
>
> Note that in XML we use <_exportcontents> due to rules on valid tag names,
> in a BND
> properties file we would use -exportcontents ( see http://aqute.biz/Code/Bnd#directives
> )
>
> couple of follow-up points:
>
> 1) if you want a good logging service for OSGi, try Pax-Logging which is
> on it's second RC:
>
>
> http://wiki.ops4j.org/confluence/display/ops4j/2007/12/19/Pax-Logging+1.0+RC2
>
>   it provides the Log4J API and many others and logging can be configured
> through OSGi
>
> 2) you can quickly create wrapper poms for third party libraries using
> pax-wrap-jar:
>
>       http://www.ops4j.org/projects/pax/construct/help/wrap-jar.html
>
>    which is part of the Pax-Construct tools (also provides bundle + bean
> archetypes)
>
> HTH
>
> As an illustration, I'm including a pom.xml that builds a bundle embedding
> > log4j (this is derivated from the felix log4j bundle).
> >
> > Thanks in advance,
> >
> > Anne
> >
> > * *
> >
> > * *
> >
> > *Anne Gérodolle
> > FT/RD/MAPS/AMS/SUME*
> >
> > *architecture de systèmes répartis*
> >
> > *distributed system architecture
> > +33 4 76 76 41 78
> > anne.gerodolle@orange-ftgroup.com*
> >
> > * *
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> > For additional commands, e-mail: users-help@felix.apache.org
> >
> >
>
>
> --
> Cheers, Stuart
>



-- 
Cheers, Stuart

Re: Classes duplicated when using Embed-dependency

Posted by Stuart McCulloch <st...@jayway.net>.
On 21/12/2007, GERODOLLE Anne RD-MAPS-GRE <an...@orange-ftgroup.com>
wrote:
>
>  Hi everybody,
>
> I have noticed that when using Embed-Dependency, if it occurs that one of
> the packages in the embedded library is either exported or declared as
> private, classes of this package are also put in the jar, so that they are
> present twice in the bundle classpath (once in the embedded jar, and once
> directly in the bundle)..
>

this is primarily because the BND tool is generic, and doesn't know about
Maven dependencies...

therefore to support embedding of dependencies the bundleplugin translates
the Embed-Dependency
instruction and the list of dependencies provided by Maven into
Include-Resource and Bundle-ClassPath
equivalents

now, because BND uses Include-Resource, Export-Package and Private-Package
to decide the contents
of the bundle, if you ask it to embed a jar and then ask it to pull some
classes into the bundle you may
of course find some duplication if the same classes are also in the embedded
jar

Is that possible to avoid this, if so how ?
>

yes - but rather than adding complex code to detect such duplication (which
would get very messy)
the solution involves using a different BND instruction (called
-exportcontents) which lets you set the
exported packages without affecting the bundle contents

for example, to wrap Log4J you'd embed the dependency and use exportcontents
to expose the API:

  <configuration>
    <instructions>
      <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
      <_exportcontents>org.apache.log4j</_exportcontents>
      <Import-Package>
                !javax.mail,
                !javax.management,
                !javax.jms,
                !javax.*,
                !com.sun.jdmk.comm,
                *
      </Import-Package>
      <Embed-Dependency>*</Embed-Dependency>
    </instructions>
  </configuration>

there's no need to set Private-Package because the jar is already embedded -
btw, you
can use <Embed-Dependency>*;inline=true</Embed-Dependency> to inline the jar

Note that in XML we use <_exportcontents> due to rules on valid tag names,
in a BND
properties file we would use -exportcontents ( see
http://aqute.biz/Code/Bnd#directives )

couple of follow-up points:

1) if you want a good logging service for OSGi, try Pax-Logging which is on
it's second RC:


http://wiki.ops4j.org/confluence/display/ops4j/2007/12/19/Pax-Logging+1.0+RC2

  it provides the Log4J API and many others and logging can be configured
through OSGi

2) you can quickly create wrapper poms for third party libraries using
pax-wrap-jar:

      http://www.ops4j.org/projects/pax/construct/help/wrap-jar.html

   which is part of the Pax-Construct tools (also provides bundle + bean
archetypes)

HTH

As an illustration, I'm including a pom.xml that builds a bundle embedding
> log4j (this is derivated from the felix log4j bundle).
>
> Thanks in advance,
>
> Anne
>
> * *
>
> **
>
> *Anne Gérodolle
> FT/RD/MAPS/AMS/SUME*
>
> *architecture de systèmes répartis*
>
> *distributed system architecture
> +33 4 76 76 41 78
> anne.gerodolle@orange-ftgroup.com*
>
> **
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>


-- 
Cheers, Stuart

Re: Classes duplicated when using Embed-dependency

Posted by Stuart McCulloch <st...@jayway.net>.
On 21/12/2007, Felix Meschberger <fm...@gmail.com> wrote:
>
> Hi Anne,
>
> You basically have two choices of adding dependencies to your bundles:
> As Export/Private-Package or by embedding as a dependency. If you embed
> the dependency as you did, the jar file is included in the bundle as
> instructed. You also listed two packages as exported and private
> packages. So these classes are put directly into the bundle.
>
> To solve this issue, you might want to inline the dependency inside the
> bundle instead of copying the jar file (and of course drop the
> Private-Package declaration as it is too much:
>
>         <Export-Package>org.apache.log4j</Export-Package>
>         ...
>         <Embed-Dependency>*;inline=true</Embed-Dependency>
>
> (Just out of my head, I did not actually test :-) )
>
> Or you might just list all packages you want to have included in the
> bundles as exported or private packages and just drop the
> Embed-Dependency element.


the third way is to use <_exportcontents> which lets you customize
the exported packages after the bundle content has been calculated

with this you can put embedded jars and locally compiled classes in
the same bundle and have full control over the exported packages :)

Regards
> Felix
>
> Am Freitag, den 21.12.2007, 12:53 +0100 schrieb GERODOLLE Anne
> RD-MAPS-GRE:
> > Hi everybody,
> >
> > I have noticed that when using Embed-Dependency, if it occurs that one
> > of the packages in the embedded library is either exported or declared
> > as private, classes of this package are also put in the jar, so that
> > they are present twice in the bundle classpath (once in the embedded
> > jar, and once directly in the bundle)..
> >
> > Is that possible to avoid this, if so how ?
> >
> > As an illustration, I'm including a pom.xml that builds a bundle
> > embedding log4j (this is derivated from the felix log4j bundle).
> >
> > Thanks in advance,
> >
> > Anne
> >
> >
> >
> > Anne Gérodolle
> > FT/RD/MAPS/AMS/SUME
> >
> > architecture de systèmes répartis
> >
> > distributed system architecture
> > +33 4 76 76 41 78
> > anne.gerodolle@orange-ftgroup.com
> >
> >
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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
>
>


-- 
Cheers, Stuart

Re: Classes duplicated when using Embed-dependency

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

You basically have two choices of adding dependencies to your bundles:
As Export/Private-Package or by embedding as a dependency. If you embed
the dependency as you did, the jar file is included in the bundle as
instructed. You also listed two packages as exported and private
packages. So these classes are put directly into the bundle.

To solve this issue, you might want to inline the dependency inside the
bundle instead of copying the jar file (and of course drop the
Private-Package declaration as it is too much:

        <Export-Package>org.apache.log4j</Export-Package>
        ...
        <Embed-Dependency>*;inline=true</Embed-Dependency>
        
(Just out of my head, I did not actually test :-) )

Or you might just list all packages you want to have included in the
bundles as exported or private packages and just drop the
Embed-Dependency element.

Regards
Felix
        
Am Freitag, den 21.12.2007, 12:53 +0100 schrieb GERODOLLE Anne
RD-MAPS-GRE:
> Hi everybody,
>  
> I have noticed that when using Embed-Dependency, if it occurs that one
> of the packages in the embedded library is either exported or declared
> as private, classes of this package are also put in the jar, so that
> they are present twice in the bundle classpath (once in the embedded
> jar, and once directly in the bundle)..
>  
> Is that possible to avoid this, if so how ?
>  
> As an illustration, I'm including a pom.xml that builds a bundle
> embedding log4j (this is derivated from the felix log4j bundle).
>  
> Thanks in advance,
>  
> Anne
>  
> 
> 
> Anne Gérodolle
> FT/RD/MAPS/AMS/SUME
> 
> architecture de systèmes répartis
> 
> distributed system architecture
> +33 4 76 76 41 78
> anne.gerodolle@orange-ftgroup.com
> 
> 
> 
> 
>  
>  
> ---------------------------------------------------------------------
> 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