Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » Using bundles with Wars(Virgo Web Apps)
Using bundles with Wars [message #1063886] Fri, 14 June 2013 18:21 Go to next message
David Cleary is currently offline David ClearyFriend
Messages: 1
Registered: June 2013
Junior Member
I'm new to Virgo and OSGi. I have an existing Servlet application that runs on Tomcat. I want to move this application to VTS and let it have access to OSGi based services that I've created.

What is the recommended approach for a Web app to gain references to services? I have little to no experience with Spring, and we are looking to stay as close to OSGi standards as possible to allow us to run in different servers.

Re: Using bundles with Wars [message #1063985 is a reply to message #1063886] Mon, 17 June 2013 06:57 Go to previous messageGo to next message
Mihael Schmidt is currently offline Mihael SchmidtFriend
Messages: 58
Registered: August 2010
You could implement a BundleActivator to get access to a bundle context and get a reference to an OSGi service with it (or better use a ServiceTracker. Don't forget to declare the activator in the manifest file.

public class Activator implements BundleActivator {

	private ServiceTracker<IStateServiceClient, IStateServiceClient> stateServiceTracker;

	private static Activator instance;

	 * Returns the shared instance
	 * @return the shared instance
	public static Activator getInstance() {
		return instance;

	public void start(BundleContext context) throws Exception {
		instance = this;

		stateServiceTracker = new ServiceTracker<IStateServiceClient, IStateServiceClient>(context,
						IStateServiceClient.class.getName(), null);;

	public void stop(BundleContext context) throws Exception {

		instance = null;

	public IStateServiceClient getStateService() {
		return stateServiceTracker.getService();


Manifest addition:
Bundle-Activator: my.package.Activator

In your web classes you can get access to the service like this:

Remember to check for a null return value. If there is no active service registered in the OSGi environment atm then null will be returned.

Hope this helps

Re: Using bundles with Wars [message #1064169 is a reply to message #1063985] Tue, 18 June 2013 04:34 Go to previous message
Violeta Georgieva is currently offline Violeta GeorgievaFriend
Messages: 269
Registered: October 2010
Senior Member

The BundleContext is available from the ServletContext attributes:

BundleContext ctxt = (BundleContext)

OSGI Enterprise Spec chapter "128.6 Interacting with the OSGi Environment"

Previous Topic:Virgo as a daemon
Next Topic:Missing part in understanding OSGI
Goto Forum:

Current Time: Tue Dec 01 04:09:41 GMT 2015

Powered by FUDForum. Page generated in 0.01916 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software