加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – unsatisfiedLinkError与本机库在sbt下

发布时间:2020-12-16 09:31:31 所属栏目:安全 来源:网络整理
导读:我使用sbt 0.13,并在sbt下使用 leveldbjni本机库(即使在 issue #358已解决)之后也有问题。已经报道了 similar issue,sbt 0.13应该提供一个解决方案,但似乎没有。所以我在这里分享我的意见。 我得到一个UnsatisfiedLinkError与以下示例应用程序。 build.sb
我使用sbt 0.13,并在sbt下使用 leveldbjni本机库(即使在 issue #358已解决)之后也有问题。已经报道了 similar issue,sbt 0.13应该提供一个解决方案,但似乎没有。所以我在这里分享我的意见。

我得到一个UnsatisfiedLinkError与以下示例应用程序。

> 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
}

我正在使用Oracle JDK 1.7和OS X 10.8.5。在sbt下运行run-main示例

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

而运行它

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

工作正常当Scala在bootclasspath上时,应用程序甚至可以成功运行:

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

任何想法为什么只有在sbt下有一个UnsatisfiedLinkError?

解决方法

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

@juereth评论说:

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.

所以这是有点预期的行为与目前的sbt设计。如果分叉工作,那么这就是你要做的事情。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读