Closed
Description
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
package wur
object Hello:
def world: String = io.Source.fromResource("hello.txt").getLines.mkString("\n")
@main def run = println(Hello.world)
core/src/main/resources/hello.txt
Hello,
World!
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>
The resource file is definitely there:
kapunga ~/whats-up-resources (master)$ jar tf core/target/scala-3.1.0/core_3-0.1.0-SNAPSHOT.jar
META-INF/MANIFEST.MF
wur/
hello.txt
wur/Hello$.class
wur/Hello.class
wur/Hello.tasty
wur/Main$package$.class
wur/Main$package.class
wur/Main$package.tasty
wur/run.class
wur/run.tasty
I've confirmed that this is not an issue with SBT or in Scala 2.13.8, where the resource loads just fine.