2017-05-10 81 views
0

我正嘗試在SBT Native Packager的幫助下創建帶有不同配置文件的構建。我有斯卡拉項目標準的項目佈局:SBT Native Packager:使用不同的配置構建相同的包

my-app 
--/project 
----/build.properties 
----/plugins.sbt 
--/src 
----/main 
------/java 
------/resources 
------/scala 
----/test 
------/java 
------/resources 
------/scala 
build.sbt 

所以我加了SBT-本機打包插件到我的項目,並決定重複SBT submodule approach

這就是我的build.sbt文件看起來像:

import sbt.Keys._ 

scalaVersion in ThisBuild := "2.12.1" 

lazy val app = project 
    .in(file(".")) 
    .settings(
    name := "backend", 
    version := "1.0", 
    libraryDependencies ++= { 
     val akkaVersion = "2.4.17" 
     val akkaHttpVersion = "10.0.5" 
     Seq(
     "com.typesafe.akka" %% "akka-actor" % akkaVersion, 
     "com.typesafe.akka" %% "akka-http" % akkaHttpVersion, 
     "com.typesafe.akka" %% "akka-http-spray-json" % akkaHttpVersion 
    ) 
    } 
) 

lazy val devPackage = project 
    .in(file("build/dev")) 
    .enablePlugins(JavaAppPackaging) 
    .settings(
    name := "backend-dev", 
    resourceDirectory in Compile := (resourceDirectory in (app, Compile)).value, 
    mappings in Universal += { 
     ((resourceDirectory in Compile).value/"dev.conf") -> "conf/application.conf" 
    } 
) 
    .dependsOn(app) 

這裏是application.conf和dev.conf(均放在src /主/資源:

akka { 
    loglevel = INFO 
    stdout-loglevel = INFO 
    loggers = ["akka.event.slf4j.Slf4jLogger"] 
    default-dispatcher { 
    fork-join-executor { 
     parallelism-min = 8 
    } 
    } 
    http { 
    server { 
     server-header = "PinPoint REST API" 
     request-timeout = "10.seconds" 
    } 
    } 
} 

database { 
    dataSourceClass = "org.postgresql.ds.PGSimpleDataSource" 
    properties = { 
    databaseName = "pg_db" 
    user = "alex" 
    password = "" 
    } 
    numThreads = 10 
} 

include "application" 

database { 
    dataSourceClass = "org.postgresql.ds.PGSimpleDataSource" 
    properties = { 
    databaseName = "pg_db_dev" 
    user = "alex" 
    password = "secure_password" 
    } 
    numThreads = 10 
} 

我運行在終端sbt devPackage/stage後,我得到了根folde新目錄「打造」該項目的r。但在裏面: build/dev/target/universal/stage/ 沒有帶可運行sh腳本的「bin」文件夾。

那麼如何解決這個問題呢?

+0

如果你有不同的主類,那麼你需要指定其中一個像mainClass在編譯:=一些(「foo.bar 。主要」)。有關更多詳細信息,請參閱http://www.scala-sbt.org/sbt-native-packager/archetypes/java_app/。 – kardapoltsev

+0

@kardapoltsev我只有一個主類 –

回答

4

如果未設置mainClass設置,並且sbt不會從您的類路徑中的jar文件自動爲您設置,Universal Packager將不會創建啓動腳本。

所有你需要做的是設置添加到您的devPackage項目:

lazy val devPackage = project 
    .in(file("build/dev")) 
    .enablePlugins(JavaAppPackaging) 
    .settings(
    name := "backend-dev", 
    resourceDirectory in Compile := (resourceDirectory in (app, Compile)).value, 
    // TODO: Use real classname here: 
    mainClass in Compile := Some("my.main.ClassName"), 
    mappings in Universal += { 
     ((resourceDirectory in Compile).value/"dev.conf") -> "conf/application.conf" 
    } 
) 
    .dependsOn(app) 
相關問題