You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For this project, I can read them just fine when running the project:
kapunga ~/whats-up-resources (master)$ sbt core/run
[info] welcome to sbt 1.6.1 (AdoptOpenJDK Java 1.8.0_282)
...
[info] running wur.run
Hello,
World!
[success] Total time: 4 s, completed Jan 17, 2022 12:12:32 AM
However, when I try and load the resources from the repl, they are not found:
kapunga ~/whats-up-resources (master)$ scala3-repl -classpath core/target/scala-3.1.0/core_3-0.1.0-SNAPSHOT.jar
Welcome to Scala 3.1.0 (11.0.10, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> import wur._
scala> Hello.world
java.io.FileNotFoundException: resource 'hello.txt' was not found in the classpath from the given classloader.
at scala.io.Source$.fromResource(Source.scala:183)
at wur.Hello$.world(Main.scala:5)
... 34 elided
scala>
as the default arg is Thread.currentThread().getContextClassLoader()
➜ whats-up-resources git:(master) scala -classpath core/target/scala-3.1.0/core_3-0.1.0-SNAPSHOT.jar
Welcome to Scala 3.1.0 (17.0.1, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> wur.run
java.io.FileNotFoundException: resource 'hello.txt' was not found in the classpath from the given classloader.
at scala.io.Source$.fromResource(Source.scala:183)
at wur.Hello$.world(Main.scala:5)
at wur.Main$package$.run(Main.scala:7)
... 30 elided
scala> Thread.currentThread.getContextClassLoader
val res0: ClassLoader = jdk.internal.loader.ClassLoaders$AppClassLoader@30946e09
scala> getClass.getClassLoader
val res1: ClassLoader = dotty.tools.repl.AbstractFileClassLoader@40bf0e15
scala>
Note that the ScalaClassLoader is on a reducing diet at #14261, where one of the conveniences in Scala 2 was to set and restore the context class loader when running script code.
Is this something I can set myself as a default? I've trimmed this problem here to the source, but the actual practical repercussions of this problem for me are that I am unable to read configuration files from the SBT console with Typesafe config (and in turn with pure-config).
Edit: Looks like I may be able to work around this in typesafe config.
I'm unable to properly load resources from the Scala 3 REPL. Reference project/code is here:
https://github.com/kapunga/whats-up-resources/branches
core/src/main/scala/wur/Main.scala
core/src/main/resources/hello.txt
For this project, I can read them just fine when running the project:
However, when I try and load the resources from the repl, they are not found:
The resource file is definitely there:
I've confirmed that this is not an issue with SBT or in Scala 2.13.8, where the resource loads just fine.
The text was updated successfully, but these errors were encountered: