SBT, include entire external directory (with the dir itself) in jar built

倾然丶 夕夏残阳落幕 提交于 2019-12-23 23:28:16

问题


I need to include entire static directory from external location in my SBT-generated JAR file (with optional folder renaming).

Adding it's path to unmanagedResourceDirectories adds its content only, not the entire directory which results in static content in the JAR root. I was playing with mappings of various sorts but with no luck.

Does anyone had similar use-case and could point me to the right direction on how to do that?

I can't modify the process that generates the static dir and can't use it's parent as it has other files/dirs I don't want inside.


回答1:


Ok, I sorted it out with a little hint I got on sbt's gitter channel. So mappings is what I needed:

mappings in (Compile, packageBin) := {
  val statics = contentOf(baseDirectory.value / "static").map {
    case (file, dest) => file -> s"webapp/$dest"
  }
  (mappings in (Compile, packageBin)).value ++ statics
}

This will take all the content from static directory and place it in the webapp directory of the resulting JAR file



来源:https://stackoverflow.com/questions/51614886/sbt-include-entire-external-directory-with-the-dir-itself-in-jar-built

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