This short tutorial is about how to run akka in an OSGi environment. I faced
a lot of problems deploying in this in plain eclipse without maven, bnd or sbt.
This example is done with the java-API, however it is also possible with Scala.
Requirements
- Eclipse Helios 3.6.2 with Scala-Plugin
- akka-1.1-modules distribution
Configuration
First we have to do some minor changes in some Manifest files in the akka project.
- Extract akka-modules-1.1.zip, e.g ~/akka
- go to akka/lib_managed/compile
- open akka-actor-1.1.jar -> META-INF/MANIFEST.MF
- delete following line: private-package: *
- Do the same with akka-typed-actor-1.1.jar
Second you have to setup a target-platform which is used to run the OSGi environment.
- Go to windows->Preferences->Plugin development->Target Platform
- Add target platform, use default
- Extract your akka-modules-1.1.zip, e.g ~/akka
- guice-all-2.0.jar
- logback-classic-0.9.24.jar
- logback-core-0.9.24.jar
- slf4j-api-1.6.0.jar
- Aspectwerkz by Jonas Bonér
The bundle
Create a new plugin project. No contributions to the UI and an activator class.
Copy the following libs into your bundle and add them to your classpath in MANIFEST.MF
- akka-actor-1.1.jar
- akka-typed-actor-1.1.jar
- akka-slf4j-1.1.jar
Create a class MyActor
import akka.actor.UntypedActor; public class MyActor extends UntypedActor { @Override public void onReceive(Object msg) throws Exception { System.out.println("Message: " + msg); } } |
Add these lines to your Activator class.
import akka.actor.ActorRef; import akka.actor.Actors; //... public void start(BundleContext bundleContext) throws Exception { Activator.context = bundleContext; ActorRef actor = Actors.actorOf(MyActor.class).start(); actor.sendOneWay("Hello You"); } |
At last you have to edit the MANIFEST.MF. It should look something like this. (I know
I may have to the smallest set of import scala packages).
Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Core Bundle-SymbolicName: de.lmu.ifi.dbs.knowing.core;singleton:=true Bundle-Version: 1.0.0.qualifier Bundle-Activator: de.lmu.ifi.dbs.knowing.core.internal.Activator Require-Bundle: org.eclipse.core.runtime, se.scalablesolutions.akka.actor;bundle-version="1.0.0", se.scalablesolutions.akka.stm;bundle-version="1.0.0", se.scalablesolutions.akka.typed.actor;bundle-version="1.0.0" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ClassPath: . Import-Package: scala;version="2.9.0.1", scala.collection;version="2.9.0.l", scala.collection.generic;version="2.9.0.1", scala.collection.immutable;version="2.8.1.final", scala.collection.interfaces;version="2.8.1.final", scala.collection.mutable;version="2.8.1.final", scala.compat;version="2.8.1.final", scala.concurrent;version="2.8.1.final", scala.concurrent.forkjoin;version="2.8.1.final", scala.io;version="2.8.1.final", scala.math;version="2.8.1.final", scala.mobile;version="2.8.1.final", scala.ref;version="2.8.1.final", scala.reflect;version="2.8.1.final", scala.reflect.generic;version="2.8.1.final", scala.runtime;version="2.8.1.final", scala.text;version="2.8.1.final", scala.util;version="2.8.1.final", scala.util.automata;version="2.8.1.final", scala.util.continuations;version="2.8.1.final", scala.util.control;version="2.8.1.final", scala.util.grammar;version="2.8.1.final", scala.util.matching;version="2.8.1.final", scala.util.parsing.ast;version="2.8.1.final", scala.util.parsing.combinator;version="2.8.1.final", scala.util.parsing.combinator.lexical;version="2.8.1.final", scala.util.parsing.combinator.syntactical;version="2.8.1.final", scala.util.parsing.combinator.testing;version="2.8.1.final", scala.util.parsing.combinator.token;version="2.8.1.final", scala.util.parsing.input;version="2.8.1.final", scala.util.parsing.json;version="2.8.1.final", scala.util.parsing.syntax;version="2.8.1.final", scala.util.regexp;version="2.8.1.final" |
Now let’s run this!
Launch configuration
- Open Run->Launch configurtions.
- Create a new OSGi Launch configuration
- Add the following bundles
- org.scala-ide.scala.library (2.8.1) (the akka scala library didn’t work for me)
- se.scalablesolutions.akka.actor
- se.scalablesolutions.akka.osgi.dependencies.bundle
- se.scalablesolutions.akka.actor.typed.actor
- se.scalablesolutions.akka.actor.stm
- com.google.inject
- Equinox Runtime Components (e,g eclipse.runtime.core,..)
- Try to launch
Hope this works for you, too!