Third-Party Libraries and OSGi
a complicated relationship
About Me
Senior Solution Architect
6 years of WCMS experience
Loves working with Java(script)
Hobbies: Biking, Hiking, Travelling
Contact: sb@eggs.de @sasusu
Sascha Brinkmann
About Us
About Us
1984 Foundation year
2004 Adobe Business Partner
2005 Adobe Authorized Training Center
2010 Winner of Siemens top+ Award
2014 100% Adobe focussed for 10 years
Employees: 45
Located: Munich, Germany
Happy Adobe customers: +40
Table of Content
Motivation
Internal
External
Integration of AEM into a heterogeneous IT systems landscape with interfaces to various subsystems.
AEM
LDAP / Active Directory
Microsoft SharePoint
Microsoft Enterprise Search (FAST)
IBM Lotus Notes Domino
SAP / Hybris
SQL Database
Rest- and Webservices
Amazon S3
Facbook
YouTube
Brightcove
FTP
Google Search Appliance
Motivation
Our work is all about solving business problems. Solutions for almost every technical challenge are provided by third party libraries from the central maven repository.
Challenge
How can I use various types of third party libraries and frameworks within my projects?
OSGi Basics
All rights reserved
Gosainkunda, Nepal
OSGi Basics - Apache Felix
Apache Felix is a fundamental element of the technology stack of the Adobe Experience Manager (AEM). It provides the environment for all Java written components.
Java Content Repository (CRX)
Apache Sling
Adobe Experience Manager (WCMS)
OSGi Runtime (Apache Felix)
OSGi Basics - Classloading
one Classloader for the �whole Java application
one Classloader per OSGi bundle
Bundle B
Bundle A
Bundle C
Bundle D
Library A
Library C
Library B
Library D
Key difference between traditional Java Applications and Applications running within OSGi.
OSGi Basics - Bundle Structure
Bundle
Manifest
Consumes
Provides
OSGi Basics - Bundle Manifest
The manifest file is a set of OSGi specific headers. It defines how to deploy and run the OSGi bundle.
Bundle Plugin
Bundle Identifier
Packages provided to other bundles
Packages Consumed from other bundles
Is created by the
during the
build process.
OSGi Basics - Maven POM Config
The Apache Felix Bundle Plugin for Maven enhances artifacts with the bundle manifest.
Apache Felix Bundle Plugin
Dependency to
other Bundle
Strategies to use third party libraries
First Option
Embedding Libraries
Second Option
Libraries as Bundles
First Option Embedding Libraries
All rights reserved
Nanuku, Fiji
First Option - Embedding Libraries
Bundle
Manifest
Same classloader for external libraries and bundle classes.
First Option - Embedding Libraries
Bundle Manifest
Libraries embedded
within the bundle
First Option - Embedding Libraries
Maven POM snippet
Dependency to be embedded with implicit scope ‘compile’
Instruction to embed all dependencies with scope compile & runtime
First Option - Embedding Libraries
Apache Felix needs to resolve all dependencies prior to start the bundle.
First Option - Embedding Libraries
Maven Artifact Dependency Tree
Transitive dependencies are not embedded automatically!
First Option - Embedding Libraries
A large number of embedded libraries within your OSGi bundle ...
… can cause an even larger number of unresolveable packages.
First Option - Embedding Libraries
Additional dependencies to resolve the missing packages.
Instruction containing a list of packages which should be ignored by Apache Felix.
Instruction to embed transitive dependencies
Further configuration parameters to adjust the generated manifest.
First Option - Embedding Libraries
The result has to be that the bundle is deployed with no unresolved packages and activated successfully
Bundle is activated and ready for operation.
First Option - Embedding Libraries
Advantages
Disadvantages
Second Option Libraries as Bundle
All rights reserved
Hollywood, USA
Second Option - Libraries as Bundle
Transformation or encapsulation of Java libraries to turn them into OSGi bundles
Searching for existing OSGi bundles
End of availability after September 2014
Just kicked off
Successor
Commandline Tool
Bundle Plugin
Second Option - Libraries as Bundle
Advantages
Disadvantages
OSGi Basics - Bundles vs. Fragments
the bundle where the fragment is attached to
Bundle
Fragment
Has its own classloader and lifecycle. Can be referenced by other bundles.
Is part of another Bundle and utilizes its classloader. Extends the imports and exports of the host bundle.
Fragment Manifest
Second Option - Libraries as Bundle
Hibernate ORM is an object-relational mapping library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database.
Entities
and DAO
JDBC
Driver
Hibernate
Core Bundle
Consumes
Entity
Bridge
Consumes
Extends
Extends
OSGi
Fragment
OSGi
Bundle
OSGi Basics - System Bundle
The system bundle is a special bundle that represents the OSGi framework itself, from within that framework.
Characteristics
Second Option - Libraries as Bundle
Apache Axis2 is a Web Services / SOAP / WSDL engine and the successor to the widely used Apache Axis SOAP stack.
System Bundle
Axis 2
Fragment
Extends
Entities
and DAO
Consumes
OSGi
Fragment
OSGi
Bundle
Dealing with Class Loader Issues
Some third party libraries make us of the current thread classloader that definitely runs within another context than the bundle class loader. To allow the third party library to access bundle resources, the current thread classloader has to be replaced for this action.
Conclusion
Your chance for remarks and questions!
All rights reserved
Los Angeles, USA
The End
All rights reserved
Nadi, Fiji
Get in Touch
Presentation
http://www.eggs.de/connectwebex2014
The Author
Sascha Brinkmann - sb@eggs.de
Sales Representative
Martin Brösamle - mb@eggs.de
Terms of Use
This work is licensed under a
Creative Commons Attribution-NoDerivatives 4.0 International License
All photos copyright © Sascha Brinkmann, all rights reserved.