12
votes

I am running my fat jar with command java -Djava.security.krb5.conf=/krb5.conf -jar my.jar.

How to run my app with this option via sbt?
$ sbt -Djava.security.krb5.conf="module\\src\\main\\resources\\krb5.conf" run doesn't work. Error:

ctl-scala>sbt -Djava.security.krb5.conf="ctl-core\src\main\resources\krb5.conf" ctl-ui-backend/run
Warning: invalid system property 'java.security.krb5.conf'
[info] Loading global plugins from C:\Users\User\.sbt\0.13\plugins
[info] Loading project definition from C:\Users\User\IdeaProjects\ctl-scala\project
[info] Set current project to ctl (in build file:/C:/Users/User/IdeaProjects/ctl-scala/)
[error] No valid parser available.
[error] ctl-core\\src\\main\\resources\\krb5.conf
[error]             ^

4
Have you tried sbt "-Djava.security.krb5.conf=ctl-core/src/main/resources/krb5.conf" ...?laughedelic

4 Answers

7
votes

Can you try sbt -J-Djava.security.krb5.conf="module/src/main/resources/krb5.conf" run

The -J causes the sbt launcher to pass those as options to the JVM.

3
votes

As sbt manual it will pass JAVA_OPTS environment variable to the java and if you can not set the variable .jvmopts will hold the java commandline arguments. so if you are in bash :

export JAVA_OPTS="-Djava.security.krb5.conf=/krb5.conf"

before sbt command will pass the argument to java runtime.

0
votes

You can force sbt to fork a new JVM when running the application, and set the desired java options with the following settings in the build.sbt file:

fork := true,
javaOptions ++= Seq(
  "-Djava.security.krb5.conf=/krb5.conf"
)

Simply run the run task and it should start the application in its own JVM with the required java options.

0
votes

Another option, is to use .sbtopts file. It should be in the root folder, next to sbt.build. Its content should be the java options, prefixed with -J, as written in previously answers, to tell sbt to pass those options to the JVM. For example its content can be:

-J-Djava.security.krb5.conf=/krb5.conf