Akka - 打包部署

原文地址

一直不知道play那个打包怎么搞的,这次发现根源了

基本步骤

  1. 声明插件
    project/plugins.sbt 下 添加 addSbtPlugin(“com.typesafe.sbt” % “sbt-native-packager” % “1.0.0-RC1”)

  2. 配置插件
    build.sbt
    如果按原文的配置,在 IDEA里是会有个报错

solution:

http://stackoverflow.com/questions/34404558/intellij-idea-and-sbt-syntax-error?rq=1

result:

build.sbt

libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http" % "10.0.4",
"com.typesafe.akka" %% "akka-http-spray-json" % "10.0.4",
"com.typesafe.slick" %% "slick" % "3.2.0",
"org.postgresql" % "postgresql" % "9.3-1100-jdbc41",
"org.slf4j" % "slf4j-nop" % "1.6.4",
"com.typesafe.slick" %% "slick-hikaricp" % "3.2.0"
)

scalaVersion := "2.12.1"

lazy val root = (project in file(".")).
enablePlugins(JavaServerAppPackaging).
settings(
name := "akka_HTTP",
version := "1.0"
)

mainClass in Compile := Some("Apiserver.WebServer")

开始打包

  • 先检查程序是否成功编译 sbt compile
  • 打包 - sbt dist
  • 进入打包目录 cd target/universal
  • 解压包 unzip akka_http-1.0.zip
  • 执行程序 akka_http-1.0/bin/akka_http Apiserver.WebServer

Apiserver.WebServer 就是入口程序的位置(package.object)