如何在IntelliJ IDEA中运行akka actor [英] How to run akka actors in IntelliJ IDEA

查看:305
本文介绍了如何在IntelliJ IDEA中运行akka actor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自Akka'网站docs:

From Akka' site docs:


这个主要方法将创建运行actor的
所需的基础设施,开始给定的主要演员并安排
整个应用程序在主要演员终止后关闭。因此
您将能够使用类似于以下
的命令运行上述代码:

This main method will then create the infrastructure needed for running the actors, start the given main actor and arrange for the whole application to shut down once the main actor terminates. Thus you will be able to run the above code with a command similar to the following:

java -classpath akka.Main example.two .HelloWorld

java -classpath akka.Main example.two.HelloWorld

那么,我如何从IntelliJ IDEA启动它?我没有找到合适的窗口。

So, how can I launch it from IntelliJ IDEA? I have not found good/proper Window for that.

对AKKA的依赖已经在项目中:

Dependecy to AKKA is already in the project:

 <dependencies>
        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-actor_2.10</artifactId>
            <version>2.2-M3</version>
        </dependency>
    </dependencies>

代码本身(你可以看到没有 main(.. 。)):

The code itself (as you can see there is no main(...) ) :

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);
    }
}


推荐答案

它好像文档和二进制发行版不同步。

It seems like the documentation and the binary distributions are not in sync.

如你所见在Github上 Main.scala 仅添加了16天之前。

As you can see here on Github the Main.scala was added just 16 days ago.

要解决此问题,您可以将依赖项版本更改为 SNAPSHOT 。将快照存储库添加到pom并将版本更改为 2.2-SNAPSHOT

To fix this you can change the dependency version to the SNAPSHOT instead. Add the snapshot repository to the pom and change version to 2.2-SNAPSHOT:

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.stackoverflow</groupId>
    <artifactId>akka-app</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>${project.artifactId}-${project.version}</name>

    <repositories>
        <repository>
            <id>akka-snapshots</id>
            <name>Akka Snapshots</name>
            <url>http://repo.akka.io/snapshots/</url>
            <layout>default</layout>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.typesafe.akka</groupId>
            <artifactId>akka-actor_2.10</artifactId>
            <version>2.2-SNAPSHOT</version>
        </dependency>

    </dependencies>

</project>

现在 akka.Main 将可用。要启动应用程序,您必须指向正确的主类并添加自己的actor类作为参数。

Now the akka.Main will be available. In order to start the application you will have to point to the correct main class and add your own actor class as an argument.

首先选择创建新的运行配置:

First chose to create a new run configuration:

然后添加一个新的应用程序:

Then add a new application:

为应用程序命名(Actor或其他内容),并将主类填写为 akka.Main 并将 HelloWorld 类添加为程序参数(记得包括完整的包):

Give the application a name (Actor or something) and fill in the main class to be akka.Main and add your HelloWorld class as Program Arguments (remember to include the full package):

现在您已准备好运行程序,只需按工具栏中的播放按钮:

And now you are ready to run the program, just press the play button in the tool bar:

Voila!

这篇关于如何在IntelliJ IDEA中运行akka actor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆