bloo bloo - 1 year ago 77
Scala Question

Using sbt-native-packager, how can I simply prepend a directory to my bash script's ${app_classpath}?

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


I'd like to prepend this directory to the runtime classpath in the bash script, and am looking for the simplest way to do that. I'd hate to maintain a separate src/main/templates/bash-template for something so simple, and am not seeing exactly how to go about it otherwise.


Answer Source

Short Answer

Define a 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 a jvmopts in src/universal/conf with


Add to build.sbt

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

Example for server_archetype: Follow the example application. A bit of description can be found here.

Long answer

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

  • classpath ordering
  • security issues

Like Typesafe Config, most libraries which use config files, provide a parameter to define the location of the configuration file. Use the parameters describe in the documentation.

It seems your are trying to run a server, which means you can use the


which is designed to read external configurations. Take a look at the example application how to use it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download