Use-case and Deployment Scenarios
How can I use and deploy Akka?
Akka can be used in different ways:
- As a library: used as a regular JAR on the classpath and/or in a web app, to be put into WEB-INF/lib
- Package with sbt-native-packager
- Package and deploy using Typesafe ConductR.
Native Packager
sbt-native-packager is a tool for creating distributions of any type of application, including an Akka applications.
Define sbt version in project/build.properties file:
sbt.version=0.13.7
Add sbt-native-packager in project/plugins.sbt file:
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.0-RC1")
Use the package settings and optionally specify the mainClass in build.sbt file:
import NativePackagerHelper._
name := "akka-sample-main-scala"
version := "2.4.0"
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.4.0"
)
enablePlugins(JavaServerAppPackaging)
mainClass in Compile := Some("sample.hello.Main")
mappings in Universal ++= {
// optional example illustrating how to copy additional directory
directory("scripts") ++
// copy configuration files to config directory
contentOf("src/main/resources").toMap.mapValues("config/" + _)
}
// add 'config' directory first in the classpath of the start script,
// an alternative is to set the config file locations via CLI parameters
// when starting the application
scriptClasspath := Seq("../config/") ++ scriptClasspath.value
Note
Use the JavaServerAppPackaging. Don't use AkkaAppPackaging (previously named packageArchetype.akka_application, since it doesn't have the same flexibility and quality as the JavaServerAppPackaging.
Use sbt task dist package the application.
To start the application (on a unix-based system):
cd target/universal/
unzip akka-sample-main-scala-2.4.0.zip
chmod u+x akka-sample-main-scala-2.4.0/bin/akka-sample-main-scala
akka-sample-main-scala-2.4.0/bin/akka-sample-main-scala sample.hello.Main
Use Ctrl-C to interrupt and exit the application.
On a Windows machine you can also use the bin\akka-sample-main-scala.bat script.
Contents