{{ !articles[0].partner.isSponsoringArticle ? "Platinum" : "Portal" }} Partner
java,osgi,scala,maven,felix,spring dm,server-side,bnd

Scala OSGi Bundle With Spring DM

Today, the OSGi bundles concept with SSAP as the application server is one of the most interesting things that developer should know. In addition, Scala is one of the most powerful languages . Reading some blogs on how to integrate Scala with OSGi : an introduction given by Neil and also the DSL concept presented by Roman , I am asking, is it possible to do Scala with Spring DM as a Scala generated .class file?

I will try here to present how the Scala language can be easy integrated with Spring DM and deployed by the Maven Felix plugin.

First of all, I downloaded one of the daily Netbeans build versions (6.5 M1 ) and installed the Scala plugin on it. Next I created a Maven project. As Java, I create a service trait and the implementation class :

package com.jtunisie.osgi.scala

trait TService {
def getMessage(): String


package com.jtunisie.osgi.scala.impl

class Service (message: String)extends TService {
def getMessage()={
def init()={
println( message);

 The service declaration will be done using Spring DM in the declarative way :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">

<bean id="service_" class="com.jtunisie.osgi.scala.impl.Service">
<constructor-arg index="0" value="sTunisie"/>

<osgi:service id="serviceOsgi" interface="com.jtunisie.osgi.scala.TService" ref="service_" />

 The init method will be called by Spring after initialisation and to check if our bundle works. Next, we modify the pom.xml to code compile: add scala plugins



and Felix bnd plugins to generate the bundle.


The idea here is that the Scala plugins are used to compile the project and as the Bnd tool inspects the .class files and not sources, it will be used generate the bundle.

$>mvn scala:compile install

 I have used the Bnd tool also on the command line to general the scala-library bundle :

$>java -jar bnd.jar wrap scala-library.jar 

Now after deploying the two bundles on Osgi container, starting our bundle we will see sTunisie on console output.

Full source project code is available : svn checkout http://osgiscala.googlecode.com/svn/trunk/ osgiscala-read-only

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks