Question

I'm building a Scala project with sbt and creating a fat jar with the sbt-assembly plugin. I'm able to add unmanaged jars (such as the Sigar jar) by adding the following to build.sbt.

unmanagedJars in Compile +=
    file("lib/hyperic-sigar-1.6.4/sigar-bin/lib/sigar.jar")

However, when I try running this, I get the following error because the *.so libraries are not included in the jar.

no libsigar-amd64-linux.so in java.library.path
org.hyperic.sigar.SigarException: no libsigar-amd64-linux.so in java.library.path
    at org.hyperic.sigar.Sigar.loadLibrary(Sigar.java:172)
    at org.hyperic.sigar.Sigar.<clinit>(Sigar.java:100)


Exception in thread "main" java.lang.UnsatisfiedLinkError: org.hyperic.sigar.ptql.SigarProcessQuery.create(Ljava/lang/String;)V
    at org.hyperic.sigar.ptql.SigarProcessQuery.create(Native Method)
    at org.hyperic.sigar.ptql.ProcessQueryFactory.getQuery(ProcessQueryFactory.java:66)
    at org.hyperic.sigar.ptql.ProcessFinder.findSingleProcess(ProcessFinder.java:44)

The libraries I want to include are in lib/hyperic-sigar-1.6.4/sigar-bin/lib/*.so and they need to be linked to a directory in the classpath within the jar. The only way I know of to do a mapping like this is:

resourceDirectory in Compile <<=
    baseDirectory{ _ / "lib/hyperic-sigar-1.6.4/sigar-bin/lib" }

This causes the *.so libraries to be added to root of the jar, but not a specific directory. How can I specify a resource map to map from lib/hyperic-sigar-1.6.4/sigar-bin/lib/*.so to a directory in the classpath in my jar? What is the terminology for what I'm trying to do?

Was it helpful?

Solution

Assuming that sigar is indeed capable of loading native libs from classpath, this should do the trick:

libraryDependencies += "org.fusesource" % "sigar" % "1.6.4" classifier("native") classifier("")

Otherwise, you need to unpack them from the jar manually and provide proper java.library.path

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top