SBT: Cross-platform way to set java.library.path?

我只是一个虾纸丫 提交于 2020-01-01 09:06:30

问题


I was working on a project that requires loading of native libraries, and so far, all development was restricted to Linux. In order to run my project, I could simply enable forking and modify java.library.path as follows:

javaOptions in run += "-Djava.library.path=some/common/path:lib/native/linux"

My question is: How can I do the same in a cross-platform way, so that I can share my build.sbt with a Windows-based developer. There are in particular three things that I couldn't figure out so far:

  • I know that SBT allows to construct platform-independent paths like "dir1" / "dir2", but I'm not aware of a cross-platform way to join multiple paths (since it is : on Linux and ; on Windows).
  • Is it possible to append either lib/native/linux or lib/native/windows dependent on the platform?
  • My approach above overwrites java.library.path -- is it possible to append instead?

回答1:


Since you can use any Scala code, you can of course do

val folderName =
  if (System.getProperty("os.name").startsWith("Windows")) "windows" else "linux"

val libPath = Seq("some/common/path", s"lib/native/$folderName").mkString(java.io.File.pathSeparator)

javaOptions in run += s"-Djava.library.path=$libPath"

though this doesn't answer your last question.



来源:https://stackoverflow.com/questions/25524109/sbt-cross-platform-way-to-set-java-library-path

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