0

I am using JBoss AS 7. As i understand, it comes with felix as the ogsi container. I have been using JBoss just as a container for a normal Java EE web application (webapp). However, I've run into so many dependency conflicts, and I'm refactoring some of my code to become bundles (for osgi). My questions are as follows.

  • Can i access osgi services from my webapp? Note that the webapp will be deployed as normal and not via osgi (it's not a webapp bundle, aka wab). If so, please provide me some links to references on how to do this. I have seen examples the other way around (accessing a webapp from an osgi bundle, but I think the webapp was deployed as a wab).
  • Is it possible to control the lifecycle of bundles (stop, uninstall, start, install) programmatically from the webapp?

thanks for any help.

1 Answer 1

1

Accessing OSGi Services from your webapp is easy.

First u need Dependencies in your MANIFEST.MF, which will be usually deployed
to the webapp/META-INF folder.

Dependencies to add are org.osgi.core and org.jboss.osgi.framework and your deployed Bundles as deployment.yourbundle:version.

Example your bundle is named "yourbundle_1.0.0.1.jar":

Manifest-Version: 1.0
Built-By: me
Build-Jdk: 1.7.0_09
Dependencies: org.osgi.core,org.jboss.osgi.framework,deployment.yourbundle:1.0.0.1

Registering your bundle as a service in the Activator class (should already be done):

public void start(BundleContext bundleContext) throws Exception {

    context.registerService(YourBundleService.class.getName(), new YourBundle(),null);
}

Accessing the OSGi BundleContext in JBoss AS needs an EJB:

@Stateless
public class OSGiServiceBean {
    @Resource
    BundleContext context;

    public YourBundleService getBundleService() {
        ServiceReference sref = context.getServiceReference(YourBundleService.class.getName());

        return (YourBundleService) context.getService(sref);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.