OSGi Support in JBoss AS7 what does that mean?
It means that AS7 comes with an OSGi framework inside that you can use to deploy your OSGi bundles in. Besides providing standards-compliant OSGi functionality, the OSGi framework in AS7 will also provide integration with non-OSGi components (such as JavaEE ones) deployed in the Application Server. This is realized by the JBoss OSGi framework that was developed from the ground up with a specific focus to provide the best possible integration with AS7. The framework is mostly the work of Thomas Diesler, although I have also been involved in writing bits of it over the past few months...
Let's give it a go!So if you're curious, here's a quick demo on how to develop a 'hello world' bundle using Eclipse and deploy it into AS7. But first start by downloading an AS7 build from here: http://www.jboss.org/jbossas/downloads. Unzip it somewhere on disk and start it up by running:
Develop your OSGi bundleYou can develop your bundle any way you like. For little projects or simply to get started I always use the Eclipse PDE that's part of the 'classic' distribution. For more serious projects I normally use maven with the Felix Bundle Plugin.
Here I simply follow the PDE wizard to develop my new TestBundle. Go File | New Project | Plug-in Project, specifying a standard OSGi Framework as the target platform:
Select the 'Hello OSGi Bundle' template:
And after hitting 'Finish' you've got a simple OSGi bundle, which has an Activator provided by the template:
For this posting I'm not making any changes to the OSGi bundle code, so let's just simply File | Export it as a deployable plugin:
Now deploy in JBoss AS7!I started AS7 somewhere using the bin/standalone.sh script and it has started up:
13:47:22,633 INFO [org.jboss.as.deployment] (pool-1-thread-2) Started FileSystemDeploymentService for directory /home/davidb/temp/as7/jboss-7.0.0.Alpha1/standalone/deployments
13:47:22,636 INFO [org.jboss.as.server] (pool-1-thread-1) JBoss AS 7.0.0.Alpha1 "Halloween" started in 3627ms. - Services [Total: 150, On-demand: 7. Started: 143]
Ok, so it has started up. A little bit higher in the log you'll also see:
13:47:21,007 INFO [osgi] Activating OSGi Subsystem
Good - OSGi is there.
Now I copy my TestBundle_1.0.0.jar into the .../jboss-7.0.0.Alpha1/standalone/deployments folder and a moment later I can see the following message in the log:
13:52:24,116 INFO [stdout] (pool-1-thread-2) Hello World!!
This is the message printed by our OSGi Bundle Activator running in AS7!
Control the framework through JMXThe OSGi Framework in JBoss AS7 does not currently come with a console application - you can control it through JMX. So let's fire up jconsole, use service:jmx:rmi:///jndi/rmi://127.0.0.1:1090/jmxrmi to connect to the Remote Process:
Let's now uninstall it using the framework MBean:
14:14:00,041 INFO [stdout] (RMI TCP Connection(13)-127.0.0.1) Goodbye World!!
14:14:00,057 INFO [org.jboss.osgi.framework.bundle.AbstractBundle] (RMI TCP Connection(13)-127.0.0.1) Bundle uninstalled: TestBundle:1.0.0
You can also control the OSGi framework through a webconsole, which can currently get installed via a separate installer, we're working on making the webconsole available in the AS7 distributable in a future milestone.
ConclusionOSGi support is now available from the very first milestone of JBoss AS7. Give it a try!
If you have any questions, reach us on the forums: http://community.jboss.org/en/jbossosgi or via JIRA: https://jira.jboss.org/browse/JBOSGI
More in-depth details can be found in Thomas Diesler's blog post: http://jbossosgi.blogspot.com/2010/11/jboss-as7-osgi-integration.html