3 Replies Latest reply on Jan 25, 2012 8:57 AM by Thomas Diesler

    JBoss module access to OSGi bundle

    Maciej Swiderski Master



      I am trying to build up a system what will have following artifacts configured:

      - JBoss Module to provide complete set of libraries that will be accessible to all application running on the AS7

      - OSGi bundles for client code that should be separated one from another


      OSGi bundles have dependencies to the configured module and import all required packages. The bundle will be responsible for activating the application, by that I mean will instantiate classes from the bundle and the module.


      So far it works as expected, but the issue comes up when module class will need to access classes in OSGi bundle. At that time ClassNotFoundException is thrown. I thought that when everything is started from OSGi bundle classes from the bundle and module will be available.


      Is there any way to get this working?



      I would like to avoid explicit dependency declaration on module as bundles are introduced to be able to dynamically add or remove client code.


      Thanks in advance


        • 1. Re: JBoss module access to OSGi bundle
          Thomas Diesler Master

          A Module can load classes from a Bundle when it creates a dependency on the Bundle. This is equivalent to creating a dependency on another Module


          builder.addManifestHeader("Dependencies", "org.osgi.core,org.jboss.modules,org.jboss.logging,org.jboss.osgi.framework,deployment.example-xservice-mab-target-bundle:0.0.0")


          A Bundle can access a Module if the Module if the Module is explicitly registered with the OSGi layer. Modules can register MSC services under a special naming convention so that they are seen by the OSGi service registry


             public static void addService(ServiceTarget serviceTarget)
                // Add the service with an alias that the OSGi layer can use to lookup the service
                ServiceBuilder<Echo> serviceBuilder = serviceTarget.addService(SERVICE_NAME, new EchoService());
                serviceBuilder.addAliases(ServiceName.of("jbosgi", "xservice", Echo.class.getName()));
                log.infof("Service added: %s", SERVICE_NAME);
                log.infof("Echo Loader: %s", Echo.class.getClassLoader());


          For more on this functionality you can study the xservice integration samples.


          So in short: every bundle is a module, but not every module is also a bundle.


          In future, we will move the OSGi Resolver a level down, so that every Module is also a Bundle - then the need of explicit registration should disappear and the two programming models should integrate more seamlessly.

          1 of 1 people found this helpful
          • 2. Re: JBoss module access to OSGi bundle
            Maciej Swiderski Master

            Thanks Thomas, xservice was what I was looking for.


            Another question, are META-INF content is loaded by module classloader? I have a jar (it is declared as resource-root) of a module and it has some xml files in META-INF but I can access them from, for instance web application. Is there any special configuration to be done in module.xml to make it visible for components that depend on the module?



            • 3. Re: JBoss module access to OSGi bundle
              Thomas Diesler Master

              For jboss-modules questions or general complaints about their documentation, you probabaly need to go to the AS team. I know however that META-INF is not automatically exported. The export attribute means that the importer re-exports the paths from the dependee. The services attribute means the the importer sees META-INF services


              <module name="com.sun.xml.bind" services="export" export="true"/>


              You can check the schema for details.