UnsatisfiedLinkError with native library under sbt [英] UnsatisfiedLinkError with native library under sbt

查看:29
本文介绍了UnsatisfiedLinkError with native library under sbt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I'm using sbt 0.13 and have issues using the leveldbjni native library under sbt (even after issue #358 has been resolved). A similar issue has already been reported for which sbt 0.13 should provide a solution but it seems it doesn't. So I'm sharing my observations here.

I'm getting an UnsatisfiedLinkError with the following example application.

  • build.sbt

    name := "example"
    
    version := "0.1"
    
    scalaVersion := "2.10.2"
    
    libraryDependencies += "org.fusesource.leveldbjni" % "leveldbjni-all" % "1.7"
    

  • build.properties

     sbt.version=0.13.0
    

  • Example.scala

    import org.fusesource.leveldbjni.internal._
    
    object Example extends App {
      NativeDB.LIBRARY.load() // loading succeeds 
      new NativeOptions() // UnsatisfiedLinkError under sbt
    }
    

I'm using Oracle JDK 1.7 and OS X 10.8.5. Running the example with run-main Example under sbt gives

[error] (run-main) java.lang.UnsatisfiedLinkError: org.fusesource.leveldbjni.internal.NativeOptions.init()V

whereas running it with

java -cp scala-library.jar:example_2.10-0.1.jar:leveldbjni-all-1.7.jar Example

just works fine. The application even runs successfully when Scala is on the bootclasspath:

java -Xbootclasspath/a:scala-library.jar -cp example_2.10-0.1.jar:leveldbjni-all-1.7.jar Example

Any ideas why there's an UnsatisfiedLinkError only under sbt?

解决方案

Any ideas why there's an UnsatisfiedLinkError only under sbt?

As @juereth commented:

Sbt is using magic classloaders to try to prevent "leaks" of native loaded libraries, and allow you to re-import the library multiple times. Sbt will actually rename the DLL/SO/jnilib and load it in a special classloader. I'm not positive if this is only a plugin feature, or something for all apps.

So this is somewhat expected behavior with the current design of sbt. If forking works, then that's what you have to do.

这篇关于UnsatisfiedLinkError with native library under sbt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆