2 Replies Latest reply on Aug 29, 2011 6:11 AM by Rico Neubauer

    Make additional modules available to OSGi bundles

    Rico Neubauer Novice

      I have an OSGi-bundle, which defines dependencies to 3rd party artifacts. e.g.

      Import-Package: org.apache.tools.ant

      Ant is available as module, so I wanted to add it to the OSGI configuration, according to https://docs.jboss.org/author/display/AS7/OSGi+subsystem+configuration and I tried all these locations:


      <property name="org.jboss.osgi.system.modules"> ... added org.apache.ant
      <property name="org.osgi.framework.system.packages.extra">... added org.apache.ant;version=1.7.1
      <modules>... added <module identifier="org.apache.ant"/>


      None of it worked.

      OSGi Web Console still shows:

      org.apache.tools.ant -- Cannot be resolved

      for my bundle.


      What is the way to go here?


      JBoss 7.0.1

        • 1. Re: Make additional modules available to OSGi bundles
          David Bosschaert Expert

          Hi Rico,


          I started playing with this and wrote a little testbundle to try it out. The bundle prints out the Ant version (obtained from the ant Main class) in the BundleActivator:



          import org.apache.tools.ant.Main;

          import org.osgi.framework.BundleActivator;

          import org.osgi.framework.BundleContext;


          public class Activator implements BundleActivator {

              public void start(BundleContext bundleContext) throws Exception {

                  System.out.println("**** Ant version: " + Main.getAntVersion());



              public void stop(BundleContext bundleContext) throws Exception {




          The manifest for my bundle is as follows:

          {code}Manifest-Version: 1.0

          Bundle-ManifestVersion: 2

          Bundle-Name: AntUsingBundle

          Bundle-SymbolicName: AntUsingBundle

          Bundle-Version: 1.0.0  

          Bundle-Activator: org.example.antusingbundle.Activator

          Import-Package: org.apache.tools.ant,



          When trying this with the ant version shipped with AS7 I (which I included with <module identifier="org.apache.ant"/> as you tried too) I was getting errors like this:

            java.lang.ClassNotFoundException: org.apache.tools.ant.launch.AntMain from [Module "org.apache.ant:main" from local module loader

          Turns out that only part of the ant libraries are shipped with AS7 and the launcher is not. In some cases you may not need the launcher and just including the ant module is enough, but at least for my test bundle (and possibly for your project) I need classes in the launcher package too.


          However it's not hard to solve this. You can download OSGi bundles for ant and its launcher from SpringSource's Enterprise Bundle Repository here:





          You can just install these as OSGi bundles in AS7, so no changes to standalone.xml are needed. For instance just copy them to the standalone/deployments directory or use the web console or maven to deploy.

          Note: the ant bundle has an optional package dependency on the launcher bundle, so the easiest way to get it all to work is to deploy the ant.launcher bundle first and then deploy the ant bundle. (If you deploy them the other way around the optional package dependency ant -> ant.launcher isn't available when its deployed and you'd have to refresh the ant bundle in order for it to see these packages).


          Now you can deploy the test bundle and you'll see output like this:


          09:14:24,864 INFO  [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-2) Install bundle: com.springsource.org.apache.tools.ant.launch:1.7.1

          09:14:24,870 INFO  [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-9) Bundle started: com.springsource.org.apache.tools.ant.launch:1.7.1

          09:14:24,895 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "com.springsource.org.apache.tools.ant.launch-1.7.1.jar"

          09:14:29,904 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-5) Starting deployment of "com.springsource.org.apache.tools.ant-1.7.1.jar"

          09:14:30,019 INFO  [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-1) Install bundle: com.springsource.org.apache.tools.ant:1.7.1

          09:14:30,027 INFO  [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-1) Bundle started: com.springsource.org.apache.tools.ant:1.7.1

          09:14:30,028 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 1) Deployed "com.springsource.org.apache.tools.ant-1.7.1.jar"

          09:14:35,038 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-16) Starting deployment of "AntUsingBundle_1.0.0.jar"

          09:14:35,048 INFO  [org.jboss.osgi.framework.internal.BundleManager] (MSC service thread 1-8) Install bundle: AntUsingBundle:1.0.0

          09:14:35,056 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 1) Deployed "AntUsingBundle_1.0.0.jar"

          09:14:35,056 INFO  [stdout] (MSC service thread 1-12) **** Ant version: Apache Ant version 1.7.1 compiled on June 27 2008

          09:14:35,056 INFO  [org.jboss.osgi.framework.internal.HostBundleState] (MSC service thread 1-12) Bundle started: AntUsingBundle:1.0.0{code}


          Notice that at the bottom you'll see the output from our bundle invoking on an Ant method: Ant version: Apache Ant version 1.7.1 compiled on June 27 2008


          Hope this helps,



          • 2. Re: Make additional modules available to OSGi bundles
            Rico Neubauer Novice

            Hi David,

            Thanks a lot. In fact as an OSGi-nub I was unsure whether the reference using the "module identifier" was correct at all. Turned out you were absolutely right, problem was the missing launcher classes.

            After having resolved the Ant-dependency, defining further dependencies to other modules worked as expected - thx.