Run project with java options via sbt

11,184

Solution 1

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.

Solution 2

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.

Solution 3

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.

Solution 4

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
Share:
11,184

Related videos on Youtube

Oleg
Author by

Oleg

PHP JavaScript .NET Java Scala developer.

Updated on September 15, 2022

Comments

  • Oleg
    Oleg over 1 year

    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]             ^

    • laughedelic
      laughedelic over 6 years
      Have you tried sbt "-Djava.security.krb5.conf=ctl-core/src/main/resources/krb5.‌​conf" ...?
  • Adrien Piquerez
    Adrien Piquerez over 3 years
    In the sbt shell you can try show <project> / fork and show <project> / javaOptions to check that their values are correct.