scalasbtscala-repl

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


I am working on Windows 10 OS and installed sbt 1.4.5 from the .msi installer from scala-lang downloads page. Now when I type sbt or sbt about in the command prompt, it works fine but as soon as I type sbt console, I get the following error message:

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\1.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$1(ClasspathUtilities.scala:62)
[error]         at scala.collection.TraversableLike.$anonfun$map$1(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$2.<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$1(Defaults.scala:2043)
[error]         at sbt.Defaults$.$anonfun$consoleTask$1$adapted(Defaults.scala:2037)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error]         at sbt.std.Transform$$anon$4.work(Transform.scala:68)
[error]         at sbt.Execute.$anonfun$submit$2(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$1(Execute.scala:282)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error]         at sbt.CompletionService$$anon$2.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

I tried identifying the error in format by running sbt --verbose and this is what I'm getting:-

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\1.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

But after this, as soon as I type console, I get the same InvalidPath exception message.

It might be elementary but I am absolutely unable to grasp where I am going wrong or how to fix this.


Solution

  • It fails because you are running this command from folder that is not an sbt project. As you can see in your error:

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

    Please add to the directory when you want to run it:

    1. project\build.properties file with the content:

      sbt.version = 1.4.5
      
    2. build.sbt file with the content:

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

    Then try to rerun this command.