A comprehensive, multi-module OSGi workspace demonstrating "pure" OSGi concepts using the programmatic approach: BundleActivators and ServiceTrackers, without Declarative Services or modern frameworks.
This project teaches OSGi fundamentals "the hard way" to build deep understanding before adopting convenience frameworks.
What This Means:
- β
Manual
BundleActivatorfor lifecycle management - β
Explicit
context.registerService()for service registration - β
ServiceTrackerwithServiceTrackerCustomizerfor dynamic service consumption - β
Hand-written
MANIFEST.MFconfiguration - β Raw JDBC (no JPA), raw Servlets (no JAX-RS), manual JSON parsing
- β NO Declarative Services (@Component, @Reference)
- β NO Blueprint, Spring DM, or OSGi Annotations
osgi-example/
βββ api β Service contract (SensorService interface, POJOs)
βββ core β Business logic (JDBC PostgreSQL implementation)
βββ web β HTTP REST API (Raw HttpServlet, ServiceTrackers)
βββ target β P2 dependency resolution (Eclipse Equinox, Jetty, JDBC)
βββ releng β Product packaging (Start levels, launcher configuration)
| Layer | Technology | Version |
|---|---|---|
| Language | Java | 17 (LTS) |
| OSGi Runtime | Eclipse Equinox | 2024-03 |
| Build System | Maven + Eclipse Tycho | 4.0.4 |
| HTTP Server | Eclipse Jetty (Equinox HTTP Service) | Latest |
| Database | PostgreSQL + JDBC Driver | 15 / 42.7.2 |
| Deployment | Docker + Docker Compose | Latest |
cd osgi-example
docker-compose up --build# GET all readings
curl http://localhost:8080/api/sensors
# POST new reading
curl -X POST http://localhost:8080/api/sensors \
-H 'Content-Type: application/json' \
-d '{"sensorId":"sensor-001","temperature":23.5,"humidity":45.2}'docker logs -f osgi-application
# Type 'ss' to see bundle status
# Type 'services' to see registered servicesThis project includes comprehensive documentation (100+ pages):
| Document | Purpose |
|---|---|
| DOCUMENTATION_INDEX.md | π Master index of all documentation |
| QUICK_REFERENCE.md | π One-page cheat sheet |
| BUILD_GUIDE.md | π¨ Complete build and setup instructions |
| ARCHITECTURE.md | π Deep technical dive and design rationale |
| DIAGRAMS.md | π Visual architecture diagrams |
| PROJECT_STRUCTURE.md | πΊοΈ File tree and navigation guide |
| OSGI_CONSOLE_REFERENCE.md | π Console commands and troubleshooting |
| DELIVERY_SUMMARY.md | β Project completion checklist |
β Start with DOCUMENTATION_INDEX.md for guided learning paths
- BundleActivator Pattern - Manual service registration and lifecycle
- ServiceTracker Pattern - Dynamic service discovery and consumption
- Service Registry - Understanding OSGi's runtime service model
- Bundle Dependencies - Import-Package vs Export-Package
- Start Levels - Controlling bundle activation order
- Eclipse Tycho - Building OSGi with Maven
- Manual service registration:
context.registerService() - ServiceTrackerCustomizer for service lifecycle events
- Raw servlet registration with HttpService
- Direct JDBC without connection pooling frameworks
- Manual JSON serialization/deserialization
- Explicit MANIFEST.MF configuration
# Maven build only
mvn clean verify
# Run the built product
cd com.github.marceloleite2604.osgiexample.releng/target/products/.../
./osgi-example -console -consoleLogNote: Requires Java 17 and Maven 3.6+
- File β Import β Maven β Existing Maven Projects
- Select
osgi-exampledirectory β Import all modules - Open
com.github.marceloleite2604.osgiexample.target/osgi-example.target - Click "Set as Active Target Platform"
- Open
com.github.marceloleite2604.osgiexample.releng/osgi-example.product - Click "Launch an Eclipse application"
Quick diagnostics:
# Check bundle status
osgi> ss
# Diagnose bundle issues
osgi> diag <bundle-id>
# List registered services
osgi> services
# View logs
docker logs -f osgi-applicationβ See OSGI_CONSOLE_REFERENCE.md for comprehensive troubleshooting
β
Pure OSGi - No shortcuts, no frameworks masking concepts
β
Production-Ready - Docker deployment with PostgreSQL
β
Comprehensive Documentation - 8 detailed guides
β
Real Integration - Database + HTTP + JSON
β
Eclipse Compatible - Import directly into Eclipse IDE
β
Educational Focus - Learn fundamentals deeply
This project demonstrates OSGi's dynamic nature:
// Core Bundle: Manual Registration
public void start(BundleContext context) {
SensorServiceImpl impl = new SensorServiceImpl();
context.registerService(SensorService.class, impl, null);
}
// Web Bundle: Dynamic Tracking
ServiceTracker<SensorService, SensorService> tracker =
new ServiceTracker<>(context, SensorService.class,
new ServiceTrackerCustomizer<>() {
public SensorService addingService(ServiceReference ref) {
// React to service appearing
}
public void removedService(ServiceReference ref, SensorService svc) {
// React to service disappearing
}
});
tracker.open();β See ARCHITECTURE.md for complete flow diagrams
- Run the project - Follow Quick Start above
- Explore the console - Use OSGi commands to see dynamic behavior
- Read the architecture - Understand the "why" behind design decisions
- Modify the code - Add features, experiment with bundles
- Compare with DS - Appreciate modern conveniences after mastering fundamentals
Marcelo Leite
GitHub: @MarceloLeite2604
Educational example demonstrating OSGi fundamentals.
Master OSGi the right way. Understand the fundamentals before using frameworks. π