David Bosschaert commented on ZOOKEEPER-425:

Hi Patrick,

You can already use this as-is in Felix or Equinox (or any other OSGi 
container). The value that the metadata in the buildxml.patch provides is that 
it exports (and imports) packages the OSGi way, which means that you can build 
a zookeeper client in its own bundle that pulls in the zookeeper classes using 
OSGi dependency management.

Here's a quick example of how to use it (using Felix 2.0.0):
{code}.../felix-framework-2.0.0>java -jar bin/felix.jar

Welcome to Felix

-> start 
Bundle ID: 4
-> start file:///.../zookeeper/build/zookeeper-3.3.0.jar
-> ps
   ID   State         Level  Name
[   0] [Active     ] [    0] System Bundle (2.0.0)
[   1] [Active     ] [    1] Apache Felix Bundle Repository (1.4.1)
[   2] [Active     ] [    1] Apache Felix Shell Service (1.4.0)
[   3] [Active     ] [    1] Apache Felix Shell TUI (1.4.0)
[   4] [Active     ] [    1] Apache Log4J (1.2.15)
[   5] [Active     ] [    1] ZooKeeper Bundle (3.3.0)

-> inspect package requirement 5
org.apache.hadoop.zookeeper [5] imports packages:
org.osgi.framework; version=1.5.0 -> org.apache.felix.framework [0]
org.osgi.util.tracker; version=1.4.0 -> org.apache.felix.framework [0]
javax.management; version=1.6.0 -> org.apache.felix.framework [0]
org.apache.log4j; version=1.2.15 -> com.springsource.org.apache.log4j [4]

-> inspect package capability 5
org.apache.hadoop.zookeeper [5] exports packages:
org.apache.zookeeper; version=3.3.0
org.apache.zookeeper.data; version=3.3.0
org.apache.zookeeper.version; version=3.3.0
org.apache.zookeeper.server; version=3.3.0
org.apache.zookeeper.server.quorum; version=3.3.0
As you can see the Log4J dependency is provided through a Log4J bundle. I'm 
using one straight from the SpringSource bundle repository (the SpringSource 
guys have turned many libraries into OSGi bundles), but you may also be able to 
find a Log4J bundle elsewhere.
After installing the Zookeeper Bundle (the jar is now also an OSGi bundle) you 
can see that it uses OSGi imports to satisfy its dependencies (e.g. it links to 
bundle 4 for its log4j imports) and it exports the zookeeper packages. The way 
to use them in OSGi-based clients is simply through imports (as 
 but additionally the client bundle will have Import-Package statements for the 
zookeeper packages in its manifest.

> Add OSGi metadata to zookeeper.jar
> ----------------------------------
>                 Key: ZOOKEEPER-425
>                 URL: https://issues.apache.org/jira/browse/ZOOKEEPER-425
>             Project: Zookeeper
>          Issue Type: Improvement
>          Components: build
>            Reporter: David Bosschaert
>            Assignee: David Bosschaert
>             Fix For: 3.3.0
>         Attachments: buildxmlpatch.patch, MANIFEST.MF, zk_patch3.patch
> After adding OSGi metadata to zookeeper.jar it can be used as both an OSGi 
> bundle as well as an ordinary jar file. 
> In the CXF/DOSGi project the buildsystem does this using the 
> maven-bundle-plugin: 
> http://svn.apache.org/repos/asf/cxf/dosgi/trunk/discovery/distributed/zookeeper-wrapper/pom.xml
> The MANIFEST.MF generated by maven-bundle-plugin is attached to this bug, 
> this works for the CXF/DOSGi project.
> If your buildsystem isn't using maven, I would advise to use bnd 
> (http://www.aqute.biz/Code/Bnd). BND defines its own ant task in which you 
> should be able to use more or less the same instructions as were used in 
> maven:
> <instructions>
>   <Bundle-Name>ZooKeeper bundle</Bundle-Name>
>   <Bundle-Description>This bundle contains the ZooKeeper 
> library</Bundle-Description>
>   <Bundle-SymbolicName>org.apache.hadoop.zookeeper</Bundle-SymbolicName>
>   <Bundle-Version>3.1.1</Bundle-Version>
>   <Import-Package>*</Import-Package>
>   <Export-Package>*;version=3.1.1</Export-Package>
> </instructions>
> Oh and one other thing. Is it really necessary to put the source code in the 
> Jar file too? I would put that in a separate source distribution :)
> See also: 
> http://mail-archives.apache.org/mod_mbox/hadoop-zookeeper-user/200905.mbox/%3c4a2009b1.3030...@yahoo-inc.com%3e

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

Reply via email to