Home > grails, osgi, plugin, release > Grails on OSGi (3): Released Grails OSGi plugin 0.1

Grails on OSGi (3): Released Grails OSGi plugin 0.1

January 3rd, 2010

The Grails OSGi plugin provides scripts to package a Grails application as an OSGi bundle. Additionally the bundle(s) may be run in an OSGi container assembled ad hoc by the excellent Pax Runner or deployed to a SpringSource DM Server.


The OSGi plugin is released under the Apache License 2.0.


Simply call grails install-plugin osgi to install the OSGi plugin.


Creating an OSGi bundle from the Grails application

grails bundle
grails prod bundle

Running the bundle

grails run-bundle
grails prod run-bundle

The application can be accessed at http://localhost:8080/myapp/.

Note: at first start the OSGi runtime is assembled, which may take some time, while Maven is downloading the internet…

Creating a zipped OSGi runtime

grails assemble-osgi-runtime
grails prod assemble-osgi-runtime

Deploy bundle to DM Server

grails dmserver deploy (Not yet implemented)

Getting around the OSGi runtime

The OSGi runtime is based on the Equinox OSGi framework, Pax Web and some additional bundles.

Web Console

The Felix Web Management Console provides excellent insight into the inner workings (see Screenshots). It can be accessed at http://localhost:8080/system/console/ with user “admin” and password “admin”.

Shell Console

The command grails run-bundle drops the user in the Equinox Shell. Typing help shows the available commands.

How it works

In order to be a valid OSGi bundle, the application is war’ed and provided with the necessary bundle manifest headers (see scripts/_Event.groovy for details).
The bundle can be created using grails bundle.

The OSGi runtime is assembled in the target/osgi directory.

Source code and Issues

The source code is hosted at GitHub, issues can be reported here.


  • make bundle generation configurable (e.g. include/exclude dependencies, …)
  • make OSGi runtime created by grails run-bundle and grails assemble-osgi-runtime configurable
  • support auto-reloading of changed artifacts
  • use Spring DM instead of Pax Web as Web extender
  • remove dependencies from bundle and package them as their own plugins (re-using existing bundles from the SpringSource Enterprise Repository
  • export main Grails beans and application context as OSGi service
  • export services as OSGi service (via static expose = 'osgi')
  • provide access to OSGi BundleContext to artifacts (controllers, services, …)
  • implement deployment to DM Server
  • consider other deployment options: Apache Karaf, …
Categories: grails, osgi, plugin, release Tags:
  1. Kim
    January 3rd, 2010 at 14:09 | #1

    It’s very interesting to follow your progress on Grails and osgi!

  2. Antoine
    January 3rd, 2010 at 19:03 | #2

    Thank you for your work! I will be trying this.

  3. January 3rd, 2010 at 19:41 | #3

    As OSGi is all about modularity, wiring services from elsewhere in the OSGi runtime, how do you do it? Happy to see that we’ll be able to make use of grails productivity on OSGi.

  4. jetztgradnet
    January 4th, 2010 at 08:44 | #4


    the OSGi plugin does not yet interact with the service registry, for now it only provides a way, to run a Grails application within an OSGi container.

    I plan to integrate interaction with OSGi services in the next version with the help of Spring DM. The application context will now about the OSGi service registry an can export and import services.

    Exporting service will then work like this:

    class MyService {
    static expose = ['osgi']

    Importing services will work like referencing any other bean:

    class MyController {
    def myOsgiService

    def index = {
    render myOsgiService.getMesssage()

    I still need to be a way to define the imported services, but that might happen through something similar to the BeanBuilder.

    Stay tuned…


  5. Matthias
    January 7th, 2010 at 19:12 | #5

    Hi Wolfgang,

    I tried this plugin and it already offers valuable functionality. There is one functionality I am missing but is planned to be implemented in the next version. It’s the ability to interact with the service registry.

    Do you have any plans when a version (next one?) with this functionality will be released?

    Thanks for the work!


  6. jetztgradnet
    January 8th, 2010 at 00:33 | #6

    Hi Matthias,

    as I’m doing this in my spare time, I can’t predict, when interaction with the OSGi service registry will be done, but most of the “research” is done and it only needs to be implemented šŸ™‚

  7. January 9th, 2010 at 13:04 | #7

    What a great resource!

  8. fkode87
    January 17th, 2010 at 15:32 | #8

    Fantastic!! Keep it up šŸ™‚

  9. tkassila
    March 6th, 2010 at 21:36 | #9

    Hi, within Grails 1.2, is there possible to register grails component as spring components and then add spring annotation or xml-def. And make this new component work as normal osgi service in Spring-DM? And is there some article or instructions how to do that? I brought just a new book: Modular Java, which is telling about OSGI and Spring. BTW: this is also very interesting to read, must try later. šŸ™‚

  10. jetztgradnet
    March 8th, 2010 at 14:41 | #10

    Version 0.1 of the OSGi plugin does not offer integration with the OSGi registry.

    The next version (0.2) will support integration using Spring DM from resources.groovy and/or Spring XML files with the Spring-DM provided OSGi namespace, but this will probably only work for apps using Grails 1.3 oder maybe 1.2.2 (both not yet released), as this requires some small changes to Grails.

    Spring DM offers many interesting possibilities, so there are a lot of exciting possibilities.

    Stay tuned!

  11. May 19th, 2010 at 20:03 | #11


    I am trying to use this plugin for a concept demonstrator but run into this issue when trying to so a run-bundle.

    Pax Runner (1.3.0) from OPS4J – http://www.ops4j.org

    / /
    / / Oops, there has been a problem!
    / /
    /__/ URL [mvn:org.ops4j.pax.web/pax-web-api/0.8.0-SNAPSHOT] could not be resolved.
    /__/ Use –log=debug to see details.

    Does not seem like that is in the maven repos. I am no big maven expert so I could be missing something.

    Gawie van Blerk

  12. May 19th, 2010 at 20:04 | #12

    @Gawie van Blerk
    Oh I also tried recompiling the plugin from source and use 0.7.2 for the pax-web-api but that seemed to have caused a host of other problems

    Gawie van Blerk

  13. jetztgradnet
    May 19th, 2010 at 23:20 | #13

    The 0.8.0 snapshot is required because of PAXWEB-148 (http://issues.ops4j.org/browse/PAXWEB-148). Unfortunately, the Pax Maven repo containing the snapshots seems to be down (http://repository.ops4j.org/mvn-snapshots/org/ops4j/pax/web). I pinged one of the main Pax authors (http://twitter.com/jetztgradnet/status/14316867970).

    So unless the Maven repo comes up again, you might be able to check out PaxWeb, build 0.8.0-snapshot yourself and adjust the links in grails-osgiplugin/grails-app/paxrunner-grails.profile, lines 128-136. You can simply change them e.g. to scan-bundle:file:/my/path/to/org.ops4j.pax.web-pax-web-api-0.8.0-SNAPSHOT.jar etc.



  14. Matthias
    May 27th, 2010 at 14:30 | #14


    Hi Wolfgang,

    has there been any progress regarding the implementation of the funtionality of accessing the osgi service registry in grails artifacts (services, controllers)? I am still very interessted in this feature and willing to contribute some implementation effort. Just drop me a line if this is an option for you…

    Thanks Wolfgang! Matthias

  15. jetztgradnet
    May 27th, 2010 at 17:04 | #15

    Hi Matthias,

    this is still very much work in progress. Progress is slow, as I didn’t have that much time during the last two month (there is still a day job to do and some “other” life as well :-)), but I’m working on it. You can follow development at GitHub: http://github.com/jetztgradnet/grails-osgi-plugin/tree/0.2.x (Note the 0.2.x branch; this is not the latest version, I have some more changes not yet pushed to GitHubin my local repo).

    I’ll try to update the plugin status on my blog over the coming weekend.



  16. Andy Edmonds
    June 2nd, 2010 at 10:55 | #16

    Any updates from the paxrunner guys regarding a maven location for 0.8? If not would anyone have a tarball of the dependencies that they could share?

  17. jetztgradnet
    June 2nd, 2010 at 13:35 | #17

    @Andy, unfortunately not. I commented on their JIRA (INFRA-88). I hope, they restore the snapshot repository soon.

  18. July 5th, 2010 at 11:38 | #18

    Y, it doesn’t work for me either… kinda makes it hard to evaluate the plugin.

    I went to comment on INFRA-88 and got what could be a licensing (“Sizelimit”) error:

    An error occurred whilst rendering this message. Please contact the administrators, and inform them of this bug. Details: ——- org.apache.velocity.exception.MethodInvocationException: Invocation of method ‘formatUser’ in class com.atlassian.jira.plugin.profile.DefaultUserFormatManager threw exception class org.codehaus.xfire.XFireRuntimeException : Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: [LDAP: error code 4 – Sizelimit Exceeded]; nested exception is javax.naming.SizeLimitExceededException: [LDAP: error code 4 – Sizelimit Exceeded]; remaining name ‘dc=codedragons,dc=com’ at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:246) at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:175) at org.apache.velocity.runtime.parser.node.ASTReference.value(ASTReference.java:327) at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:144) at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:175) at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:220) at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:230) at org.apache.velocity.runtime.directive.VelocimacroProxy.render(VelocimacroProxy.java:172) at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:114) at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:230) at org.apache.velocity.Template.merge(Template.java:256) …

    I feel that I’m already out on the edge with what I am trying to do. I’d hoped to do the evaluation quickly so I can justify and (if need be) caveat the grails in osgi approach.

  19. July 5th, 2010 at 12:04 | #19

    Can we point to another set of snapshots repository? Would the files at http://svn.apache.org/viewvc/maven/ help?

  20. jetztgradnet
    July 6th, 2010 at 00:10 | #20

    I have no affiliation with OPS4J and PAX, other than using their software, so I have no influence on their use of the Maven repository for snapshots, sorry.

    I’m actively working on version 0.2 of the OSGi plugin, which does not need PAX Web anymore. Greatest draw back currently: I does not yet support Hibernate, so you can run only Grails apps without GORM. But I will find a way around this.

    Please send a comment if you want to try it out and thanks for still bothering and not giving up!

  21. July 7th, 2010 at 09:42 | #21

    Thanks – I’ve emailed Alin to ask whether he plans to restore the repository.

    If its quick to try I’ll certainly have a go. I agree I would need the GORM functionality.

    Cheers, Martin.

  22. July 7th, 2010 at 15:59 | #22

    I’ve voted on http://issues.ops4j.org/browse/PAXWEB-148 – perhaps anyone else here blocked by this issue can do the same.

  23. July 7th, 2010 at 16:21 | #23

    Iā€™m actively working on version 0.2 of the OSGi plugin, which does not need PAX Web anymore.

    Ok. Might be wise as I did notice that development of paxweb has slowed down – no release since Oct 2009. Let’s hope though.

    jetztgradnet :
    The 0.8.0 snapshot is required

    Looks like Paxweb 0.8.0 wasn’t released, http://wiki.ops4j.org/display/paxweb/Download shows 0.7.1 as the latest finished build. https://scm.ops4j.org/repos/ops4j/qa/pax/ shows web-0.7.2/ as the latest in dev.

    you might be able to check out PaxWeb, build 0.8.0-snapshot yourself and adjust the links in grails-osgiplugin/grails-app/paxrunner-grails.profile

    I checked out 0.7.1 and am presently doing a ‘mvn package’ to build it. From there I’ll try these changes.

  24. July 7th, 2010 at 22:28 | #24

    adjust the links in grails-osgiplugin/grails-app/paxrunner-grails.profile

    Ok, so, for others interested, this is what I fixed up in /Users/martincleaver/SoftwareDevelopment/Grails/grails-osgi-plugin/grails-app/paxrunner-grails.profile:

    Found this section:

    # Pax Web including Jetty (6.1.9)

    And replaced with


    # find ~/SoftwareDevelopment/OSGi/paxweb/web-0.7.1 -name ‘*.jar’

    Now, simply running grails run-bundle in my target app is not enough, because I am not yet using the version of grails-osgi-plugin that I just modified. For that I must

    grails package-plugin
    Welcome to Grails 1.3.2 – http://grails.org/
    Licensed under Apache Standard License 2.0
    Grails home is set to: /Users/martincleaver/grails

    Base Directory: /Users/martincleaver/My Documents/5.SoftwareDevelopment/OSGi/paxrunner/runner-build
    Resolving dependencies…
    Dependencies resolved in 1323ms.
    Running script /Users/martincleaver/grails/scripts/PackagePlugin_.groovy
    Environment set to development
    Application is pre-Grails 0.5, please run: grails upgrade

    martincleaver@ip-85-160-218-111.eurotel.cz:~/SoftwareDevelopment/OSGi/paxrunner/runner-build 22:23:06 559$ grails upgrade
    Welcome to Grails 1.3.2 – http://grails.org/
    Licensed under Apache Standard License 2.0
    Grails home is set to: /Users/martincleaver/grails

    Base Directory: /Users/martincleaver/My Documents/5.SoftwareDevelopment/OSGi/paxrunner/runner-build
    Resolving dependencies…
    Dependencies resolved in 1768ms.
    /Users/martincleaver/My Documents/5.SoftwareDevelopment/OSGi/paxrunner/runner-build does not appear to be part of a Grails application.
    The following commands are supported outside of a project:
    Run ‘grails help’ for a complete list of available scripts.

    So, there’s something fishy going on that prevents me from building the new version. Any clues? Thanks, Martin.

  25. jetztgradnet
    July 7th, 2010 at 22:36 | #25

    Hi Martin,

    thanks for your hard work!

    The latter commands fail, because you are not in the directory containing the grails OSGi plugin, but in the directory, where (I assume) you built pax runner or pax web.

    With Grails 1.3.2 you don’t need to repackage the OSGi plugin, if you simply change BuildConfig.groovy in your test app to contain a line like this:

    grails.plugin.location.’Osgi’ = ‘/path/to/changed/grails-osgi-plugin’

    This way Grails uses the plugin inline and you don’t have to package and migrate it.



  26. July 7th, 2010 at 22:57 | #26

    Thanks for the feedback and email, Wolfgang.

    Almost there!

    Now I see:

    org.ops4j.pax.runner.platform.PlatformException: [http://download.eclipse.org/equinox/drops/R-3.4.2-200902111700/org.eclipse.equinox.supplement_1.1.0.v20080421-2006.jar] could not be downloaded

    Seems it might need to come from http://archive.eclipse.org/equinox/drops/R-3.4.2-200902111700/ instead?

  27. jetztgradnet
    July 8th, 2010 at 03:21 | #27

    Hi Martin,

    I put in some work and created a snapshot version of OSGi plugin 0.2, which you can use instead of the 0.1 version.

    0.2-SNAPSHOT does not need Pax Web anymore. Hibernate and GORM works in this release.

    To try it out, perform the following steps:
    1. Create a Grails App (using Grails 1.3.2)
    2. Install OSGi plugin 0.2 SNAPSHOT:
    grails install-plugin http://github.com/downloads/jetztgradnet/grails-osgi-plugin/grails-osgi-0.2.zip
    3. Change Config.groovy
    Set grails.logging.jul.usebridge = false
    4. Create some Domain classes and controllers
    5. Run app in OSGi environment
    grails run-bundle -forceBundle
    The parameter -forceBundle is necessary, whenever something changed in your app, otherwise the bundle won’t be rebuilt.

    Have fun,


  28. July 8th, 2010 at 08:11 | #28

    Awesome, Wolfgang, thanks so much.

    Did you really stay up till 3am to finish this for me? If so, an even bigger thanks.

    Additionally I needed some jars to fix UNRESOLVED DEPENDENCIES:

    wget http://osgi-in-action.googlecode.com/svn-history/r21/trunk/lib/blueprint/spring-osgi-io-2.0.0.M1.jar
    $ mv spring-osgi-io-2.0.0.M1.jar lib/
    wget http://osgi-in-action.googlecode.com/svn-history/r21/trunk/lib/blueprint/spring-osgi-core-2.0.0.M1.jar
    mv spring-osgi-core-2.0.0.M1.jar lib/

  29. jetztgradnet
    July 8th, 2010 at 10:12 | #29

    You’re welcome.

    So did it work for you? Do you have your app up and running? Please note: the URL will be http://localhost:8080/myapp-version/ instead of http://localhost:8080/myapp/ like grails run-app does it

    I don’t know why the Spring DM jars won’t get resolved and downloaded, they are specified as dependencies of the OSGi plugin. Maybe the SpringSource Enterprise Repository (EBR) ditched them or was offline?

    BTW, the code on GitHub (http://github.com/jetztgradnet/grails-osgi-plugin/) is now up to date, if you want to have a look or change anything.

    Have fun,


  30. July 8th, 2010 at 18:29 | #30

    Yes, I just tried it! It is up, thank you!

    Now I have to make my application work. šŸ˜‰

Comments are closed.
Fork me on GitHub