How to use sbt-native-packager, how can I just add a directory to my bash script $ {app_classpath}?

My project uses sbt-native-packager with packageArchetype.java_application . During the sbt stage, I have a task that generates some final Safeafe-style configuration file, which I then copy to:

target/universal/stage/conf/application.conf

I would like to add this directory to the runtime class path in a bash script, and I'm looking for the easiest way to do this. I would really like to maintain a separate src / main / templates / bash -template template for something so simple, and I don’t see exactly how to do it otherwise.

Thank!

+4
source share
3 answers

Short answer

Define package mapping

mappings in Universal <+= (packageBin in Compile, sourceDirectory ) map { 
    (_, src) =>
    // we are using the reference.conf as default application.conf
    // the user can override settings here
    val conf = src / "main" / "resources" / "reference.conf"
    conf -> "conf/application.conf"
}

Create jvmopts in src / universal / conf with

-Dconfig.file=/<installation-path>/conf/application.conf

Add to build.sbt

bashScriptConfigLocation := Some("${app_home}/../conf/jvmopts")

Example for server_archetype: Follow the application. A little description can be found here .

Long answer

Changing the classpath directly is not supported by sbt-native-packager, as this can cause problems like

  • class ordering
  • safety problems

Like Configafe Config, most libraries that use configuration files provide an option for locating the configuration file. Use the options described in the documentation .

, , ,

packageArchetype.java_server

. , .

+9

, , . - , :

, , , , / sbt-native-packager script, :

private lazy val ClasspathPattern = "declare -r app_classpath=\"(.*)\"\n".r

bashScriptDefines :=  bashScriptDefines.value.map {
                              case ClasspathPattern(classpath) => "declare -r app_classpath=\"/path/to/some/external/lib/*:" + classpath + "\"\n"
                              case _@entry => entry
                          },
+2

:

scriptClasspath in bashScriptDefines ~= (cp => "../conf" +: cp),

, .

"../conf" .

, SBT:

import com.typesafe.sbt.packager.Keys.bashScriptDefines
import com.typesafe.sbt.packager.Keys.scriptClasspath
+1

Source: https://habr.com/ru/post/1534332/


All Articles