问题
I have a production application in Akka that I start with the following option:
-Djava.library.path="./native/"
(with native
directory containing a library libsigar-amd64-linux.so
) and everything is fine.
When I type sbt test
I'm facing the following error:
[executorTest-akka.actor.default-dispatcher-13] DEBUG Sigar - no libsigar-amd64-linux.so in java.library.path
org.hyperic.sigar.SigarException: no libsigar-amd64-linux.so in java.library.path
I tried to modify build.sbt
with:
libraryDependencies in Test ++= file("native/libsigar-amd64-linux.so")
but it didn't help.
回答1:
JVM will only load libraries from the java.library.path
. The libraryDependencies
is for declaring managed dependencies (as e.g. jars).
> help libraryDependencies
Declares managed dependencies.
What you need is to specify the aforementioned java.library.path
for your tests. You have two choices.
One you can run tests in a forked JVM, add following lines to your build.sbt
javaOptions in Test += s"""-Djava.library.path=${baseDirectory.value / ".native"}"""
fork in Test := true
Second you can run sbt using (note this will override the java.library.path
for the whole process), which in case you're not forking tests, will be visible in tests
sbt -Djava.library.path=./native
回答2:
If you run with forked tests you need to pass the -Djava.library.path
to the jvm that runs the tests, you can do that in your sbt-config with something like this:
javaOptions in Test += "-Djava.library.path=\"./native/\""
If you do not run with forked tests, the tests is run inside the sbt-jvm and you need to pass -Djava.library.path
to that jvm, using the SBT_OPTS
environment variable for example.
来源:https://stackoverflow.com/questions/24385458/how-to-declare-dependency-on-native-so-library-for-tests