How to set system property for xsbt-web-plugin's jetty()?

偶尔善良 提交于 2019-12-10 22:48:08

问题


I've migrated my project to 0.13.5 and started using the xsbt-web-plugin.

I'd like to configure logback to be using a configuration file outside the classpath which is set by a system property logback.configurationFile (so I can keep the logconfig outside the war file).

Previously I would simply set:

System.setProperty("logback.configurationFile", "/some/path/logback.xml")

inside the project/build.scala and logback would pick it up.

However, after upgrading sbt to 0.13.5 and migrating to the xsbt-web-plugin system properties set in sbt don't seem to be available at runtime(jetty).

I've tried setting system properties in different ways, also by passing it along using the -D flag when starting sbt.

On the sbt console I can see the property:

eval sys.props("logback.configurationFile")
[info] ans: String = /some/path/logback.xml

But it's not available inside the webapp.

Any ideas on how to set system properties to be available inside the webapp?

I've tried both jetty() and tomcat(). Same behaviour.

Update: I ended up with:

jetty(options = new ForkOptions(runJVMOptions = Seq("-Dlogback.configurationFile=/some/path/logback.xml")))

that works.


回答1:


Use javaOptions in container += "-Dlogback.configurationFile=/some/path/logback.xml" as described in Set forked JVM options.

javaOptions alone (without in container) should work, too, as could be seen in inspect actual under Dependencies and Delegates:

[play-new-app] $ inspect actual container:javaOptions
[info] Task: scala.collection.Seq[java.lang.String]
[info] Description:
[info]  Options passed to a new JVM when forking.
[info] Provided by:
[info]  {file:/Users/jacek/sandbox/play-new-app/}root/container:javaOptions
[info] Defined at:
[info]  /Users/jacek/sandbox/play-new-app/build.sbt:26
[info] Dependencies:
[info]  */*:javaOptions
[info] Delegates:
[info]  container:javaOptions
[info]  *:javaOptions
[info]  {.}/container:javaOptions
[info]  {.}/*:javaOptions
[info]  */container:javaOptions
[info]  */*:javaOptions
[info] Related:
[info]  */*:javaOptions


来源:https://stackoverflow.com/questions/26526848/how-to-set-system-property-for-xsbt-web-plugins-jetty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!