Grails on OSGi (3): Released Grails OSGi plugin 0.1
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.
License
The OSGi plugin is released under the Apache License 2.0.
Installation
Simply call grails install-plugin osgi to install the OSGi plugin.
Usage:
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.
Roadmap
- make bundle generation configurable (e.g. include/exclude dependencies, …)
- make OSGi runtime created by
grails run-bundleandgrails assemble-osgi-runtimeconfigurable - 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
BundleContextto artifacts (controllers, services, …) - implement deployment to DM Server
- consider other deployment options: Apache Karaf, …



It’s very interesting to follow your progress on Grails and osgi!
Thank you for your work! I will be trying this.
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.
@JS:
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…
Wolfgang
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!
Matthias
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
What a great resource!
Fantastic!! Keep it up
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.
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!
Hi
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.
Regards
Gawie van Blerk
@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
Regards
Gawie van Blerk
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.
HTH,
Wolfgang
@jetztgradnet
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
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.
Regards,
Wolfgang
@jetztgradnet
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?
@Andy, unfortunately not. I commented on their JIRA (INFRA-88). I hope, they restore the snapshot repository soon.
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.
Can we point to another set of snapshots repository? Would the files at http://svn.apache.org/viewvc/maven/ help?
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!
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.
I’ve voted on http://issues.ops4j.org/browse/PAXWEB-148 – perhaps anyone else here blocked by this issue can do the same.
Ok. Might be wise as I did notice that development of paxweb has slowed down – no release since Oct 2009. Let’s hope though.
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.
I checked out 0.7.1 and am presently doing a ‘mvn package’ to build it. From there I’ll try these changes.
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:
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
So, there’s something fishy going on that prevents me from building the new version. Any clues? Thanks, Martin.
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.
HTH,
Wolfgang
Thanks for the feedback and email, Wolfgang.
Almost there!
Now I see:
Seems it might need to come from http://archive.eclipse.org/equinox/drops/R-3.4.2-200902111700/ instead?
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.zip3. 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 -forceBundleThe parameter
-forceBundleis necessary, whenever something changed in your app, otherwise the bundle won’t be rebuilt.Have fun,
Wolfgang
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:
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 ofhttp://localhost:8080/myapp/likegrails run-appdoes itI 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,
Wolfgang
Yes, I just tried it! It is up, thank you!
Now I have to make my application work.