DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

How to create/generate OSGi bundles from existing third-party jars?

Singaram Subramanian user avatar by
Singaram Subramanian
·
Dec. 02, 11 · Interview
Like (0)
Save
Tweet
Share
14.13K Views

Join the DZone community and get the full member experience.

Join For Free

If you get to work with OSGi, you often have to generate OSGi bundles. Any third party jar can’t be included straightaway in your application – you need to create an OSGi bundle of the jar you want to include.

Quoting from http://blog.springsource.org/2008/02/18/creating-osgi-bundles/,

a bundle is a JAR file that:

  • Contains [...] resources
  • Contains a manifest file describing the contents of the JAR file and providing information about the bundle
  • Can contain optional documentation in the OSGI-OPT directory of the JAR file or one of its sub-directories

In short, a bundle = jar + OSGI information (specified in the JAR manifest file – META-INF/MANIFEST.MF), no extra files or predefined folder layout are required. This means that all it takes to create a bundle from a jar, is to add some entries to the JAR manifest.

Before you use any tool/plugin to generate OSGi bundles, do search in public OSGi repositories like SpringSource Enterprise Bundle Repository etc. to see if there’s an OSGi bundle already made available.

Assume that we’re wrapping a vanilla jar file, c3p0-0.9.1.2.jar, which is a popular connection pool library, as an OSGi bundle. Here’s the way I do it:

1. Download aQute’s BND tool from here: http://dl.dropbox.com/u/2590603/bnd/biz.aQute.bnd.jar
2. Create bnd.property file (See below for a sample file).

bnd.properties
version: 0.9.1.2
Bundle-ManifestVersion: 2
Bundle-SymbolicName: com.mchange.v2.c3p0
Bundle-Version: ${version}
Bundle-Name: c3p0
Export-Package: *;version=${version}
Import-Package: *

3. Run this command: java -jar biz.aQute.bnd.jar wrap -properties bnd.properties c3p0-OSGi.jar
4. You’ll get  c3p0-OSGi.bar, which needs to be renamed to  c3p0-OSGi.jar. That’s it, you have the OSGi bundle.

Related articles
  • Creating OSGi projects using Eclipse IDE and Maven (singztechmusings.wordpress.com)
  • OSGi adoption by Large Scale Java-based Enterprise Software Platforms – LinkedIn Case Study (singztechmusings.wordpress.com)
  • Working with OSGi and Maven in Eclipse IDE (singztechmusings.wordpress.com)
  • imabonehead: Building LinkedIn’s Next Generation Architecture with OSGi (slideshare.net)
  • Apache moves Geronimo to OSGi base (infoworld.com)

From http://singztechmusings.wordpress.com/2011/11/29/how-to-creategenerate-osgi-bundles-from-existing-third-party-jars/

JAR (file format)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Required Knowledge To Pass AWS Certified Solutions Architect — Professional Exam
  • 10 Best Ways to Level Up as a Developer
  • The 5 Books You Absolutely Must Read as an Engineering Manager
  • Create Spider Chart With ReactJS

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: