Scala does not read file from resources folder after compiling

While running my app with Intellij Idea , I had no problems with resource folder. It was reading files and passing tests. It was implemented like this:

val resourcesPath = getClass.getResource("/lexical/stopWords.csv").getPath
val source = fromFile(resourcesPath)
val text = try source.mkString finally source.close()

But when I started to test my server with docker-compose, I started to get error about my files, It couldn’t read them anymore. So I have to change my code again:

val source = Source.fromInputStream(getClass().getClassLoader().getResourceAsStream(path))(Codec.UTF8)
val text = try source.mkString finally source.close()
  • (Codec.UTF8) -> makes sure all characters readable
  • getClass().getClassLoader().getResourceAsStream(path) -> will consider all paths to be absolute paths.