How can I use Accu Actors in a Java application?

I would like to use Akkoy actors in Java.

I downloaded akka-1.0.zipand added akka-actor-1.0.jarto my "build path" in Eclipse.

Then I wrote this Actor class:

package com.example;

import akka.actor.UntypedActor;

public class MyActor extends UntypedActor {

    public void onReceive(Object message) throws IllegalArgumentException {
        if (message instanceof String) {
            System.out.println("Received: " + message);
        } else throw new IllegalArgumentException("Unknown message: " + message);
    }
}

But I get errors in Eclipse:

The type scala.Option cannot be resolved.
The type scala.Some cannot be resolved.
The type scala.PartialFunction cannot be resolved.
The type scala.ScalaObject cannot be resoled.

Do I need to add any files to my "build path" or what am I doing wrong? I do not find the documentation useful.

Update: I added scala-library.jarto my build path and the above erros disappeared. But I get an error when compiling and starting the application:

Exception in thread "main" java.lang.NoClassDefFoundError: net/lag/configgy/ConfigMap
    at akka.actor.Actors.actorOf(Actors.java:70)
    at com.example.ActorTest.main(ActorTest.java:9)
Caused by: java.lang.ClassNotFoundException: net.lag.configgy.ConfigMap
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 2 more

Here is the main class in which I use my actor:

package com.example;

import akka.actor.ActorRef;
import akka.actor.Actors;

public class ActorTest {

    public static void main(String[] args) {
        ActorRef myActor = Actors.actorOf(MyActor.class);
        myActor.start();
        System.out.println("My Actor started");
    }

}
+5
source share
4

akka-1.0.zip scala-library.jar. .

, zip lib_managed, . , .

, maven. Akka: http://scalablesolutions.se/akka/repository/se/scalablesolutions/akka/

+2

; Maven, .

+2

I see this problem using Akka in a Java project in Eclipse with a Scala installation installed. The problem goes away when using an Eclipse instance without the Scala IDE installed. Eclipse maybe confusing two Scala libraries around?

+1
source

I don't know the Akka actors, but it looks like you need scala support (libs in the build path).

0
source

All Articles