过去几天我一直试图掌握AKKA和我得到的演员模型,我通过消息等进行沟通,但是如果我能得到一个简单的HelloWorld项目来编译我就会被拦截。这是单个helloWorld.java文件......我在这里包含了两个类(Actors)......
import akka.actor.Props;
import akka.actor.UntypedActor;
import akka.actor.ActorRef;
public class helloWorld extends UntypedActor {
@Override
public void preStart() {
// create the greeter actor
final ActorRef greeter =
getContext().actorOf(Props.create(Greeter.class), "greeter");
// tell it to perform the greeting
greeter.tell(Greeter.Msg.GREET, getSelf());
}
@Override
public void onReceive(Object msg) {
if (msg == Greeter.Msg.DONE) {
// when the greeter is done, stop this actor and with it the application
getContext().stop(getSelf());
} else unhandled(msg);
}
}
public class Greeter extends UntypedActor {
public static enum Msg {
GREET, DONE;
}
@Override
public void onReceive(Object msg) {
if (msg == Msg.GREET) {
System.out.println("Hello World!");
getSender().tell(Msg.DONE, getSelf());
} else unhandled(msg);
}
}
这是我在终端(Ubunut)中使用的命令......
java -classpath $AKKA_HOME/lib/scala-library.jar:$AKKA_HOME/lib/akka/akka-actor_2.10-2.2.1.jar:$AKKA_HOME/lib/akka/config-1.0.2.jar akka.Main helloWorld
这是我得到的例外......
Exception in thread "main" java.lang.ClassNotFoundException: helloWorld
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:270)
at akka.actor.ReflectiveDynamicAccess$$anonfun$getClassFor$1.apply(DynamicAccess.scala:67)
at akka.actor.ReflectiveDynamicAccess$$anonfun$getClassFor$1.apply(DynamicAccess.scala:66)
at scala.util.Try$.apply(Try.scala:161)
at akka.actor.ReflectiveDynamicAccess.getClassFor(DynamicAccess.scala:66)
at akka.Main$.main(Main.scala:32)
at akka.Main.main(Main.scala)
有人可以提供任何建议吗?
提前致谢
答案 0 :(得分:0)
您使用的类路径仅包含依赖项jar,而不包含helloWorld.class(您当然也需要编译)。如果你使用
javac -classpath $AKKA_HOME/lib/scala-library.jar:$AKKA_HOME/lib/akka/akka-actor_2.10-2.2.1.jar:$AKKA_HOME/lib/akka/config-1.0.2.jar helloWorld.java
然后你会在当前的工作目录中找到它,这意味着你只需添加“:”。到类路径,使其工作。另一个建议是避免使用默认包,并始终将您的类放入像package tsume
这样的命名包中。