由于 InvalidPath 异常,无法使用 'sbt console' 启动 Scala REPL

Unable to launch Scala REPL using 'sbt console' due to InvalidPath exception

我正在开发 Windows 10 OS 并从 scala-lang 下载页面的 .msi 安装程序安装了 sbt 1.4.5。现在,当我在命令提示符中键入 sbtsbt about 时,它工作正常,但只要我键入 sbt console,我就会收到以下错误消息:

C:\Users\anka2\Scala_Samples\Variables>sbt console
[warn] Neither build.sbt nor a 'project' directory in the current directory: "C:\Users\anka2\Scala_Samples\Variables"
c) continue
q) quit
?c
[warn] No sbt.version set in project/build.properties, base directory: C:\Users\anka2\Scala_Samples\Variables
[info] welcome to sbt 1.4.5 (Oracle Corporation Java 1.8.0_271)
[info] loading global plugins from C:\Users\anka2\.sbt.0\plugins
[info] set current project to variables (in build file:/C:/Users/anka2/Scala_Samples/Variables/)
[error] java.nio.file.InvalidPathException: Illegal char <"> at index 0: "C:\Windows\System32
[error]         at sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
[error]         at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
[error]         at sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
[error]         at sun.nio.fs.WindowsPath.parse(WindowsPath.java:94)
[error]         at sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:255)
[error]         at java.io.File.toPath(File.java:2234)
[error]         at sbt.internal.inc.classpath.ClasspathUtil$.$anonfun$javaLibraryPaths(ClasspathUtilities.scala:62)
[error]         at scala.collection.TraversableLike.$anonfun$map(TraversableLike.scala:285)
[error]         at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:36)
[error]         at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:33)
[error]         at scala.collection.mutable.WrappedArray.foreach(WrappedArray.scala:38)
[error]         at scala.collection.TraversableLike.map(TraversableLike.scala:285)
[error]         at scala.collection.TraversableLike.map$(TraversableLike.scala:278)
[error]         at scala.collection.AbstractTraversable.map(Traversable.scala:108)
[error]         at sbt.internal.inc.classpath.ClasspathUtil$.javaLibraryPaths(ClasspathUtilities.scala:62)
[error]         at sbt.internal.inc.classpath.ClasspathUtil$$anon.<init>(ClasspathUtilities.scala:50)
[error]         at sbt.internal.inc.classpath.ClasspathUtil$.toLoader(ClasspathUtilities.scala:48)
[error]         at sbt.internal.inc.classpath.ClasspathUtil$.makeLoader(ClasspathUtilities.scala:115)
[error]         at sbt.internal.inc.classpath.ClasspathUtil$.makeLoader(ClasspathUtilities.scala:103)
[error]         at sbt.Defaults$.$anonfun$consoleTask(Defaults.scala:2043)
[error]         at sbt.Defaults$.$anonfun$consoleTask$adapted(Defaults.scala:2037)
[error]         at scala.Function1.$anonfun$compose(Function1.scala:49)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219(TypeFunctions.scala:62)
[error]         at sbt.std.Transform$$anon.work(Transform.scala:68)
[error]         at sbt.Execute.$anonfun$submit(Execute.scala:282)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error]         at sbt.Execute.work(Execute.scala:291)
[error]         at sbt.Execute.$anonfun$submit(Execute.scala:282)
[error]         at sbt.ConcurrentRestrictions$$anon.$anonfun$submitValid(ConcurrentRestrictions.scala:265)
[error]         at sbt.CompletionService$$anon.call(CompletionService.scala:64)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error]         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error]         at java.lang.Thread.run(Thread.java:748)
[error] (Compile / console) java.nio.file.InvalidPathException: Illegal char <"> at index 0: "C:\Windows\System32
[error] Total time: 0 s, completed Jan 17, 2021 11:25:34 AM

我尝试通过 运行 sbt --verbose 来识别格式错误,这就是我得到的结果:-

C:\Users\anka2>sbt --verbose
# Executing command line:
"C:\Program Files\Java\jdk1.8.0_271\bin\java.exe"
-Dfile.encoding=UTF-8
-Xms1024m
-Xmx1024m
-Xss4M
-XX:ReservedCodeCacheSize=128m
-cp
"C:\Program Files (x86)\sbt\bin\sbt-launch.jar"
 xsbt.boot.Boot

[info] welcome to sbt 1.4.5 (Oracle Corporation Java 1.8.0_271)
[info] loading global plugins from C:\Users\anka2\.sbt.0\plugins
[info] loading project definition from C:\Users\anka2\project
[info] set current project to anka2 (in build file:/C:/Users/anka2/)
[info] sbt server started at local:sbt-server-ff142d10856e0dc0f951
[info] started sbt server

但在此之后,只要我输入 console,我就会收到相同的 InvalidPath 异常消息。

这可能是初级的,但我完全无法理解我哪里出错了或如何解决这个问题。

失败是因为您运行从不是 sbt 项目的文件夹中执行此命令。正如您在错误中看到的那样:

Neither build.sbt nor a 'project' directory in the current directory: "C:\Users\anka2\Scala_Samples\Variables"

请在需要时添加到目录运行:

  1. project\build.properties 文件内容:

    sbt.version = 1.4.5
    
  2. build.sbt 文件内容:

    name := "test213"
    version := "0.1"
    scalaVersion := "2.13.4"
    

然后尝试重新运行这个命令。

问题是 SBT 缺少几个文件。 修复:使用 cmd

  1. cd 到一个空文件夹。
  2. C:\Users\USER\scala_sample_learning> sbt new scala/hello-world.g8
  3. 成功执行第 2 步后,cmd 将提示您输入名称,输入 hello-world
  4. 现在您可以使用 sbt 控制台了