“sbt 服务器已经启动。”从 wsl2 ubuntu 启动 sbt 时出错

问题描述 投票:0回答:2

我已经在 wsl2 ubuntu 安装程序上使用 sdkman 安装了 sbt。目前已安装 sbt 1.4.2。当我尝试从终端启动它时,它给出了

sbt server is already booting. Create a new server? y/n (default y)
如果我选择n,什么也不会发生。如果我选择 y,则 sbt 开始。我想要做的是能够在没有错误消息的情况下启动 sbt。因为这种行为会破坏 Visual Studio 代码上的金属。

我检查了sbt源代码,发现下面的方法打印了错误消息 - in

sbt/main/src/main/scala/sbt/Main.scala

private def getSocketOrExit(
      configuration: xsbti.AppConfiguration
  ): (Option[BootServerSocket], Option[Exit]) =
    try (Some(new BootServerSocket(configuration)) -> None)
    catch {
      case _: ServerAlreadyBootingException
          if System.console != null && !ITerminal.startedByRemoteClient =>
        println("sbt server is already booting. Create a new server? y/n (default y)")
        val exit = ITerminal.get.withRawInput(System.in.read) match {
          case 110 => Some(Exit(1))
          case _   => None
        }
        (None, exit)
      case _: ServerAlreadyBootingException =>
        if (SysProp.forceServerStart) (None, None)
        else (None, Some(Exit(2)))
    }
}

因此,调用

new BootServerSocket(configuration)
会引发异常。异常来源是 BootServerSocket.java 中的以下方法;

static ServerSocket newSocket(final String sock) throws ServerAlreadyBootingException {
    ServerSocket socket = null;
    String name = socketName(sock);
    try {
      if (!isWindows) Files.deleteIfExists(Paths.get(sock));
      socket =
          isWindows
              ? new Win32NamedPipeServerSocket(name, false, Win32SecurityLevel.OWNER_DACL)
              : new UnixDomainServerSocket(name);
      return socket;
    } catch (final IOException e) {
      throw new ServerAlreadyBootingException();
    }
  }

我检查了

isWindows
方法,它返回 false。所以
new UnixDomainServerSocket(name)
部分正在运行。并且不知何故它无法创建unix域服务器套接字。这就是我所发现的一切。有没有办法来解决这个问题?或者这是一个错误?

sbt wsl-2
2个回答
4
投票

将我的项目文件移动到 wsl2 中的目录后,问题就解决了。我的项目文件之前位于 Windows 目录中。


0
投票

就我而言,这是通过“退出”当前的 sbt shell(在 intellij 中)来解决的

© www.soinside.com 2019 - 2024. All rights reserved.