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:
target/universal/stage/conf/application.conf
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.
Thanks!
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
-Dconfig.file=/<installation-path>/conf/application.conf
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
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
packageArchetype.java_server
which is designed to read external configurations. Take a look at the example application how to use it.
The following setting:
scriptClasspath in bashScriptDefines ~= (cp => "../conf" +: cp),
Allows you to do exactly what you need.
In this specific example I prepend the "../conf" directory to the classpath entries.
Also, you need to import the following configuration keys to your build SBT:
import com.typesafe.sbt.packager.Keys.bashScriptDefines
import com.typesafe.sbt.packager.Keys.scriptClasspath
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With