0

We have a Scala web application using Finagle, where we try to read some files from the classpath. It works in the unit test environment, but when assembled and run from Intellij Idea we get a nullpointer exception because it can't read the file. I tried different versions

val s = Thread.currentThread().getContextClassLoader.getResourceAsStream("env.txt")
val parent = Thread.currentThread().getContextClassLoader.getParent()
val s2 = parent.getResourceAsStream("env.txt")
val s3 = this.getClass.getResourceAsStream("env.txt")
val s4 = ClassLoader.getSystemResourceAsStream("env.txt")

It all fails with a nullpointer exception, which I interpret it can't find the files on the classpath.

To start the assembled jar I run:

java -classpath temp-conf -jar project-app/target/scala-2.12/cea-app.jar

Someone has a clue?

dr jerry
  • 9,768
  • 24
  • 79
  • 122

1 Answers1

0

Scala sbt-assembly documenatation;

NOTE: If you use -jar option for java, it will ignore -cp, so if you have multiple JAR files you have to use -cp and pass the main class: java -cp "jar1.jar:jar2.jar" Main

dr jerry
  • 9,768
  • 24
  • 79
  • 122