Professional Documents
Culture Documents
CONTENTS INCLUDE:
What is Equinox
n
Developing Your First Bundle
n
Launching an Equinox System
n
Programming Model
n
Key Equinox Execution Options
n
Hot Tips and more... By Jeff McAffer
We then look at runtime elements of Equinox and OSGi – adopted, these terms became synonyms.
lifecycle, classloading, key APIs and strategies for inter-bundle
collaboration (e.g., services and extensions).
Getting started
Extension
specification
Launching an Equinox system
Figure 2
Now that you have a bundle, lets run it. Open the launch
The manifest for a bundle specifies identity, lifecycle and
configuration dialog using Run > Run Configurations… menu
dependency information.
entry. Double click on OSGi Framework. On the Bundles tab,
uncheck the Target Platform box in the list of bundles and then Bundle-RequiredExecutionEnvironment: J2SE-1.5
click Add Required Bundles. You should now have two bundles Bundle-SymbolicName: org.equinoxosgi.helloworld
Bundle-Version: 1.0.0
selected, yours and org.eclipse.osgi. Click Run. The OSGi
Bundle-Name: Hello World
console will appear and your println message should appear. Bundle-ManifestVersion: 2
osgi> Hello, World Bundle-ClassPath: .
Bundle-Activator: org.equinoxosgi.helloworld.Activator
To get a sense of what’s happening and the kind of dynamic Export-Package: org.equinoxosgi.helloworld
behavior that is inherent in Equinox, type ss in the console. This Import-Package: org.osgi.framework; version="1.3.0"
shows a “short status” of the system. Each bundle is listed along
with its numeric id and current state. Notice that your bundle is Important headers
ACTIVE. That means its start() method has been called. Header Description/Use
Extensions
Extensions and extension points are the traditional Eclipse
!
collaboration mechanism. The extension registry is a declarative
Figure 3
means for one bundle to hook into another in a well-defined way.
In the Whiteboard approach, the roles are reversed – the various For example, the UI bundle might expose a menu extension point
to allow the addition of menu entries. Bundles then contribute
participants register as services and one or more coordinators
extensions detailing their menu entries. The UI bundle then
discover all services and call them. A sort of “don’t call us, we’ll
presents the menus using the information given declaratively.
call you” approach. In Figure 4 we see the screens registering
When the menu is selected, the class contributed in the extension
services and the shell consuming these services to render the UI.
is instantiated and run. Figure 5 captures this example behavior
between the UI and some bundle called Hyperbola.
!
Figure 4
Figure 5
Pro Con
Registration simple, pure POJOs, same requires code to run to register Extension Registry Manages the declarative relationships between bundles
programming model everywhere
Extension Point Bundles open themselves for configuration/extension
Whiteboard can be declarative, enables lazy very difficult to do with pure
class loading POJOs Extension Bundle extends another by contributing an extension
The eclipse.exe can read parameters from an associated ini file Equinox website and wiki The home of the Equinox project.
by the same name but with the .ini extension (e.g., eclipse.ini). • http://eclipse.org/equinox Find downloads, tutorials and
You can specify any parameters in this file but it is recommend • http://wiki.eclipse.org/equinox getting started guides, project plans,
to only specify the vm location and the vm arguments in this file contribute patches and bug reports.
and use the config.ini file for others. OSGi Alliance The home of OSGi. Get copies of
• http://osgi.org the spec and find more information
The <launcher>.ini must be named after the executable name on the technology.
(e.g., eclipse.exe reads eclipse.ini, whereas launcher.exe reads
launcher.ini) and every parameter must be specified on a new Equinox OSGi book The definitive guide to Equinox. Get
line in the file. Here is an example of such a file specifying the • http://equinoxosgi.org comprehensive code samples and
connect to the book on Safari.
vm location and some parameters:
-vm Apache Felix The home of the Felix OSGi
c:/myVm/java.exe • http://felix.apache.org implementation. Get more bundles
-vmargs and find other OSGi-minded people
-Dms40M
AB O U T T H E A U T H O R R E C O MM E N D E D B O O K
Jeff McAffer Equinox and OSGi incrementally
Jeff McAffer leads the Eclipse Equinox OSGi, RCP and Orbit teams guides you through building an
and is co-founder and CTO of EclipseSource. He is one of the archi- application. It focuses on OSGi
tects of the Eclipse Platform and a co-author of The Eclipse Rich Client and its application to building
Platform and the upcoming book Equinox and OSGi. He co-leads the highly modular and dynamic
RT PMC and is a member of the Eclipse Project PMC, the Tools Project systems. Equinox and Eclipse are
PMC and the Eclipse Foundation Board of Directors and the Eclipse used throughout, but the lessons
Architecture Council. Jeff is currently interested in all aspects of Eclipse components from and code should be applicable to
developing and building bundles to deploying, installing and ultimately running them. anyone writing OSGi systems.
Publications
n The Eclipse Rich Client Platform (Addison Wesley) BUY NOW
n Equinox and OSGi - The power behind Eclipse (Addison Wesley) books.dzone.com/books/equinox-osgi
DZone, Inc.
1251 NW Maynard
ISBN-13: 978-1-934238-38-7
Cary, NC 27513
ISBN-10: 1-934238-38-4
50795
888.678.0399
DZone communities deliver over 4 million pages each month to 919.678.0300
more than 1.7 million software developers, architects and decision
Refcardz Feedback Welcome
makers. DZone offers something for everyone, including news, refcardz@dzone.com
$7.95
tutorials, cheatsheets, blogs, feature articles, source code and more. Sponsorship Opportunities 9 781934 238387
“DZone is a developer’s dream,” says PC Magazine. sales@dzone.com
Copyright © 2008 DZone, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechani- Version 1.0
cal, photocopying, or otherwise, without prior written permission of the publisher. Reference: Equinox and OSGi: The Power Behind Eclipse, Jeff McAffer, Paul VanderLei and Simon Archer,
Addison-Wesley Professional, Last Updated on Safari: 2008/11/18, Publication Date: May 01, 2009 (estimated)