Gert Vanthienen's blog

Tuesday, January 26, 2010

Scala on Karaf

Over the holiday season, I had a bit of spare time to work the Camel Scala DSL again. While doing this, I realized that it was a bit too hard to actually use the Scala DSL on Karaf (need to configure Maven to use both the Scala plugin and the Felix bundle plugin to build the deployable jar).

Wouldn't it be nice to just drop a Scala source file in Karaf's deploy folder and get everything done automatically? With this idea in mind, I started a new project called Slang on the FUSE Forge to add support for additional languages to Karaf.

You can now try out a first shot at the Scala language support - you still have to build it yourself at the moment, but once you installed the feature on Karaf, you can just drop this source file in the deploy folder:


import org.fusesource.slang.scala.common.ScalaActivator

package org.fusesource.slang.scala.examples

class Activator extends ScalaActivator {

  publish(new HelloWorldServiceImpl())
   .as[HelloWorldService]
}

class HelloWorldServiceImpl extends HelloWorldService {
  def hello = println("Saying hello")
}

trait HelloWorldService {
  def hello
}


The result will be a bundle on Karaf that exports the HelloWorldService interface and has published the HelloWorldServiceImpl in the OSGi Service Registry. Next on my todo list is to actually get it to run the Camel route built in the Scala DSL this way.

Labels: ,