SBT:跨平台的方式来设置java.library.path吗? [英] SBT: Cross-platform way to set java.library.path?
问题描述
我当时正在从事一个需要加载本机库的项目,到目前为止,所有开发都仅限于Linux.为了run
我的项目,我可以简单地启用派生并按如下所示修改java.library.path
:
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"
我的问题是:我该如何以跨平台的方式做同样的事情,以便与基于Windows的开发人员共享我的build.sbt.到目前为止,我尤其无法解决三件事:
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:
- 我知道SBT允许构造独立于平台的路径,例如
"dir1" / "dir2"
,但是我不知道跨平台的方式来连接多个路径(因为在Linux上是:
,在Windows上是;
). - 是否可以根据平台附加
lib/native/linux
或lib/native/windows
? - 我上面的方法覆盖了
java.library.path
-可以附加吗?
- 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
orlib/native/windows
dependent on the platform? - My approach above overwrites
java.library.path
-- is it possible to append instead?
推荐答案
由于您可以使用任何Scala代码,因此您当然可以这样做
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.
这篇关于SBT:跨平台的方式来设置java.library.path吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!