我正在尝试使用scala -akka from sbt.
我的sbt文件如下:
name := "hello"
version := "1.0"
scalaVersion := "2.9.1"
resolvers += "akka" at "http://repo.akka.io/snapshots"
libraryDependencies ++= Seq(
"com.codahale" % "simplespec_2.9.0-1" % "0.4.1",
"com.typesafe.akka" % "akka-stm" % "2.0-SNAPSHOT"
)
我代码:import akka._
object HelloWorld {
def main(args: Array[String]) {
println("Hello, world!")
}
}
当我做sbt compile
时,我得到
]# **sbt compile**
[info] Set current project to default-91c48b (in build file:/var/storage1/home/test_user/dev_scala/hello/)
[info] Compiling 1 Scala source to /var/storage1/home/test_user/dev_scala/hello/target/scala-2.9.2/classes...
[error] /var/storage1/home/test_user/dev_scala/hello/src/main/scala/hw.scala:3: not found: object akka
[error] import akka._
[error] ^
[error] one error found
[error] (compile:compile) Compilation failed
[error] Total time: 3 s, completed May 22, 2013 8:59:08 PM
请建议。
EDIT2:根据下面的评论。这是新的SBT文件
name := "hello"
version := "1.0"
scalaVersion := "2.9.1"
resolvers += "akka" at "http://repo.akka.io/snapshots"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.1.4",
"com.codahale" % "simplespec_2.9.0-1" % "0.4.1",
"com.typesafe.akka" % "akka-stm" % "2.0-SNAPSHOT" ,
"com.typesafe.akka" %% "akka-actor" % "2.2-M3",
"com.typesafe.akka" %% "akka-slf4j" % "2.2-M3",
"com.typesafe.akka" %% "akka-remote" % "2.2-M3",
"com.typesafe.akka" %% "akka-testkit" % "2.2-M3"% "test"
)
有什么想法吗?
您的项目没有正确的依赖项。
你要加上这个"com.typesafe.akka" %% "akka-actor" % "2.0.5"
。这是akka核心模块的主要依赖项。此外,最好为您的akka项目添加以下内容:
"com.typesafe.akka" %% "akka-actor" % "2.0.5",
"com.typesafe.akka" %% "akka-slf4j" % "2.0.5",
"com.typesafe.akka" %% "akka-remote" % "2.0.5",
"com.typesafe.akka" %% "akka-agent" % "2.0.5",
"com.typesafe.akka" %% "akka-testkit" % "2.0.5"% "test"
要使用actor,你应该导入akka.actor._
好的,这个构建文件为我工作
name := "hello"
version := "1.0"
scalaVersion := "2.10.1"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.2-M3",
"com.typesafe.akka" %% "akka-slf4j" % "2.2-M3",
"com.typesafe.akka" %% "akka-remote" % "2.2-M3",
"com.typesafe.akka" %% "akka-agent" % "2.2-M3",
"com.typesafe.akka" %% "akka-testkit" % "2.2-M3" % "test"
)
不要忘记reload
和update
您的项目在sbt
你的akka-actor依赖绝对不能和你的其他依赖不同。你添加的任何依赖绝对不能依赖于不同版本的akka,否则你会有一个非常混乱的依赖树。
如果你刚开始使用,最好使用当前版本。在撰写本文时,Coltrane 2.2-M3是当前的。
你可以根据需要添加更多的akka库…但这是基于我们在prod:
中运行的实际项目的基本起点。name := "app"
organization := "com.yourorg"
version := "0.0.1-SNAPSHOT"
scalaVersion := "2.10.1"
scalacOptions ++= Seq("-unchecked", "-deprecation")
resolvers ++= Seq(
"Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
)
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.2-M3",
"com.typesafe.akka" %% "akka-slf4j" % "2.2-M3",
"com.typesafe.akka" %% "akka-testkit" % "2.2-M3"
)
更新24.03.2019
要使用Akka Actors,您需要以下依赖项:
sbt:
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.5.21",
"com.typesafe.akka" %% "akka-testkit" % "2.5.21" % Test
)
Gradle :
dependencies {
compile group: 'com.typesafe.akka', name: 'akka-actor_2.12', version: '2.5.21'
testCompile group: 'com.typesafe.akka', name: 'akka-testkit_2.12', version: '2.5.21'
}
Maven的:
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.12</artifactId>
<version>2.5.21</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-testkit_2.12</artifactId>
<version>2.5.21</version>
<scope>test</scope>
</dependency>
有关Akka集群,Akka流,Akka Http, Alpakka等的更多信息和依赖代码片段,请查看:https://akka.io/docs/