Java “;没有可用的锁”;当运行sbt cmd时

Java “;没有可用的锁”;当运行sbt cmd时,java,sbt,Java,Sbt,为了构建spark项目,我尝试使用sbt。发生以下异常: java.io.IOException: No locks available at sun.nio.ch.FileChannelImpl.lock0(Native Method) at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:871) at java.nio.channels.FileChannel.tryLock(FileChannel.j

为了构建spark项目,我尝试使用sbt。发生以下异常:

java.io.IOException: No locks available
    at sun.nio.ch.FileChannelImpl.lock0(Native Method)
    at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:871)
    at java.nio.channels.FileChannel.tryLock(FileChannel.java:962)
    at xsbt.boot.Locks$GlobalLock.withChannel$1(Locks.scala:88)
    at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries$1(Locks.scala:81)
    at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock$1.apply(Locks.scala:102)
    at xsbt.boot.Using$.withResource(Using.scala:11)
    at xsbt.boot.Using$.apply(Using.scala:10)
    at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:62)
    at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:52)
    at xsbt.boot.Locks$.apply0(Locks.scala:31)
    at xsbt.boot.Locks$.apply(Locks.scala:28)
    at xsbt.boot.Update.apply(Update.scala:100)
    at xsbt.boot.Launch.update(Launch.scala:279)
    at xsbt.boot.Launch.xsbt$boot$Launch$$retrieve$1(Launch.scala:149)
    at xsbt.boot.Launch$$anonfun$3.apply(Launch.scala:157)
    at scala.Option.getOrElse(Option.scala:120)
    at xsbt.boot.Launch.xsbt$boot$Launch$$getAppProvider0(Launch.scala:157)
    at xsbt.boot.Launch$$anon$2.call(Launch.scala:142)
    at xsbt.boot.Locks$GlobalLock.withChannel$1(Locks.scala:98)
    at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries$1(Locks.scala:81)
    at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock$1.apply(Locks.scala:102)
    at xsbt.boot.Using$.withResource(Using.scala:11)
    at xsbt.boot.Using$.apply(Using.scala:10)
    at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:62)
    at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:52)
    at xsbt.boot.Locks$.apply0(Locks.scala:31)
    at xsbt.boot.Locks$.apply(Locks.scala:28)
    at xsbt.boot.Launch.locked(Launch.scala:178)
    at xsbt.boot.Launch.app(Launch.scala:93)
    at xsbt.boot.Launch.app(Launch.scala:91)
    at xsbt.boot.Launch$.run(Launch.scala:51)
    at xsbt.boot.Launch$$anonfun$explicit$1.apply(Launch.scala:45)
    at xsbt.boot.Launch$.launch(Launch.scala:65)
    at xsbt.boot.Launch$.apply(Launch.scala:16)
    at xsbt.boot.Boot$.runImpl(Boot.scala:31)
    at xsbt.boot.Boot$.main(Boot.scala:20)
    at xsbt.boot.Boot.main(Boot.scala)
Error during sbt execution: java.io.IOException: No locks available
我尝试过的sbt版本:0.11.3-2和0.13.0 我还尝试更改sbt引导目录以避免权限问题


你知道我做错了吗。

我真的不知道是什么错了,但我怀疑你的问题可能类似于。您是否使用项目和/或sbt副本和/或NFS装载上的主目录进行构建?您是否尝试过完全从本地磁盘进行构建?

SBT依赖jvm的属性“user.home”作为工作目录,并且似乎在其中获取锁,如果您的“user.home”指向未安装NFS锁服务的NFS目录,则会出现“无可用锁”错误

我已经多次遇到这个错误(另一个例子是maven试图在$HOME/.m2/..下获取一些锁)。您有两种选择:

  • 安装NFS锁定服务
  • 通过传递属性-Duser.home=/path/in/local/disk,告诉sbt不要在NFS中使用您的目录。如。
    • sbt clean compile-Duser.home=/disk1/myhome

    • 默认情况下,sbt在启动或执行依赖项解析时尝试获取独占锁。这是为了避免缓存损坏,或者删除另一个进程正在使用的JAR文件(这可能会导致一些非常奇怪的错误)

      这种锁定通常与分布式文件系统不兼容。有时它甚至会在本地文件系统上失败,并出现意外的实现。检查您的FS,看看Java是否支持对其进行锁定

      您应该能够通过以下方式禁用此锁定:

      sbt -Dsbt.boot.lock=false
      
      另外,如果您有自己的
      sbt.boot.properties
      文件,则需要以下内容:

      [boot]
      lock: false
      

      这将禁用启动器内部的锁定功能,这反过来会禁用所有使用此功能的sbt项目的锁定。当然,这意味着sbt中的一切,尽管一些插件可能直接使用JDK锁定API。

      是的,我们尝试在~/.ivy2/中获取一个锁,以确保只有一个进程接触到ivy缓存,以避免我们遇到的损坏问题。您可以禁用此功能。谢谢通知。我认为获取锁以避免腐败对我来说是必要的,maven无论如何都会在$HOME中获取锁,所以我只使用本地$HOME。不幸的是,我公司的群集没有NFS锁。。。