Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Should I learn OSGi? What's the point?

April 5, 2016
Mary Cochran
Related topics:
Java
Related products:
Red Hat OpenShift

Share:

    Recently, I have been hearing a lot of debate around whether it is worth someone's time to learn OSGi.  Doing a simple Google search on "OSGi usability" returns results filled with phrases such as "not easy to use", "unproductive", "developer burden", and "going away".  However, you will also find that it solves a lot of common issues in the JVM, particularly issues around class loading.  So is learning OSGi worth your time?

    What is OSGi?

    OSGi is meant to solve common class loading issues that are seen in traditional Java EE environments; it is a set of specifications that are used in the creation of jars with extra manifest information to define dependencies and class loading behavior. These "special" jars are called "bundles", which are the primary packaging structure for OSGi-enabled applications.

    Think about a large Maven project, for example. Often you will come across dependency chains where multiple versions of the same dependency are built into the same application - your system then will choose the dependency that is listed first and load that one (typically alphabetically.) This can cause behavior that is different between development and production, if the ordering changes at all between the two environments. Wouldn't you rather be making that decision yourself, or leave it to a skilled architect?

    In an OSGi application, if your service is exposed to 2 different versions of the same package you are required to specify which version to use. Conflicts must be resolved, meaning your build, or potentially the startup of your service itself, will fail  (depending on where the dependency issue is).

    OSGi is meant to be modular, and bundles typically have high cohesion and loose coupling.  Each bundle performs its own function, and another will do something different. Bundles are encouraged to interact to each other through exposed and imported types on the class path, and through services (shared instances of a class with a managed life-cycle.)

    Benefits of OSGi

    • Modularity - Code is broken down into very small chunks, making it easier to reuse code later.  In addition, many third party applications already provide bundles that can be used in your application.
    • Less downtime - OSGi containers such as Karaf allow for the stopping, updating, restarting, etc of a single bundle without taking down the whole application (assuming that it is properly designed). In addition, multiple versions of your code can run at the same time on the same container. Keep in mind if you are exposing your services on URLs, the URLs for each service version must differ; otherwise, you'd never know which version of the service you are trying to hit.
    • Isolated class loading - If you build a service that needs one version of `org.json` and build a second service that needs a newer version of that same package, you can have both versions deployed in your container at the same time without causing class loading conflicts. Since the versions for each dependent bundle will be specified and loaded as defined in their individual manifests, OSGi will ensure that the correct version is provided to each.
    • Fine-grained import/export control - When creating a bundle, both import and export packages are defined.  'Import' packages are what your bundle pulls in from other bundles, while 'export' packages are what your bundle makes available to other bundles that depend on it.  Instead of having all the code in your bundle exposed to other bundles, you have control to pick and choose what is visible to your consumers.

    Downfalls of OSGi

    • Developer burden & Learning curve - I mentioned this above, and it is truly a downfall worth mentioning; learning OSGi is not easy. It takes time to understand how class loading works, and why you are running into dependency chain issues.  For those coming from a Java EE background, the learning curve can be steep.
    • Compatibility of Spring Dynamic Modules (DM) - The use of Spring is fairly common in enterprise projects, so compatibility with Spring is important. Although the use of a pure XML spring implementation is supported in Fuse 6.2, the annotation based implementation of Spring is only supported through Spring 3.x, not Spring 4.  In Spring 4, Spring DM was removed.  This means that getting an annotation based Spring implementation using Spring 4 to run on an OSGi container is not only a pain, but nearly impossible and unsupported.
    • Technical risk & Client burden - Not all architects, production support groups, or clients are willing to take a risk on OSGi if they know nothing about it.

    How is OSGi related to Micro-Services?

    Recently there has been a lot of buzz around Micro Services being the future of integration.  While that may be true, OSGi is the gateway to micro-services.  What is OSGi's focus?  Modularity, class loading control, and small services that have a very focused purpose or even just a single purpose.  That sounds a lot like micro-services.

    The main difference is that micro-services are expected to each run in their own containers allowing for more control over development and updates, whereas an OSGi container might be host to multiple services.

    Why is OSGi relevant to Red Hat?

    Red Hat's JBoss Fuse is an open source, lightweight, and modular integration platform with a built in Enterprise Service Bus (ESB). Fuse has traditionally run on Apache Karaf, an OSGi container implementation, which has historically meant that most consultants and developers working with JBoss Fuse had to also learn OSGi; however, Fuse 6.2 allows the ESB to run on Karaf or JBoss EAP - a Java application server with a light-weight modular core. OSGi is not required.

    This is not without limitation, as running on the EAP Camel subsystem places some restrictions on Apache Camel components - some are and some are not compatible. The JBoss R&D teams have put some effort into fully impementing OSGi in JBoss EAP, but there has been some debate over whether or not this will continue.

    Conclusion

    Learning OSGi is definitely worth your time, just don't get caught up in the details (at least in the beginning.) First, focus on learning something that takes advantage of OSGi, like Camel.  It has flexibility to run in both OSGi and Java EE containers, so even if you decide OSGi is not for you, you'll still have learned something useful.

    Then, once you have gotten your feet wet with some basics, start slow and with simple examples for OSGi.  Pay attention to the modularity, class loading, and concepts of OSGi rather than looking at how to configure a complex project to run in Karaf. Even if the future is micro-services, learning and understanding more about modularity and class loading will help will all of your future Java development.

    Last updated: January 18, 2023

    Recent Posts

    • A deep dive into Apache Kafka's KRaft protocol

    • Staying ahead of artificial intelligence threats

    • Strengthen privacy and security with encrypted DNS in RHEL

    • How to enable Ansible Lightspeed intelligent assistant

    • Why some agentic AI developers are moving code from Python to Rust

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue