Opentaps OSGI Proof Of Concept Tutorial
From Opentaps Wiki
Jump to navigationJump to search
war/pom.xml defines the bundles which are used, including both remote bundles
<dependency> <groupId>javax.servlet</groupId> <artifactId>com.springsource.javax.servlet</artifactId> </dependency>
and our bundles:
<dependency> <groupId>org.opentaps</groupId> <artifactId>org.opentaps.core.persistence</artifactId> <version>0.0.1-SNAPSHOT</version> <scope>provided</scope> </dependency>
Each bundle in turn contains its own pom.xml which defines itself, its version, its build process (using Maven), and its dependencies.
The pom.xml defines an Activator class to manage the bundle:
<Bundle-Activator>org.opentaps.core.persistence.Activator</Bundle-Activator>
This class has the start(BundleContext context) and stop(BundleContext context) methods which controls what happens when the bundle is started and stopped. The important things it does are:
- Register services, which binds implementation to interfaces. For example, we can bind org.opentaps.core.security.useradmin.internal.UserAdminImpl to org.osgi.service.useradmin.UserAdmin
context.registerService(UserAdmin.class.getName(), new UserAdminImpl(), null);