this.javaClass.getResource("dummy.pdf")
fetches a path relative to the path of the compiled file in the assembled JAR.
The assembled JAR is the contents of both
src/main/resources
and the compiled sources in
src/main/kotlin/
combined together, but each Kotlin file will be placed into a directory matching the package.
A file
src/main/resources/foo/bar/my/application/dummy.pdf
will be copied into the JAR with a path of
/foo/bar/my/application/dummy.pdf
.
A class with an FQN of
<http://foo.bar.my|foo.bar.my>.application.MyClass
will be compiled into the JAR with a path of
/foo/bar/my/application/MyClass.class
So
MyClass::class.javaClass.getResource("dummy.pdf")
will try and load a file
relative to
/foo/bar/my/application/
, and that file doesn’t exist. Instead, you can load a file with an absolute path by adding a leading
/
this.javaClass.getResource("/foo/bar/my/application/dummy.pdf")
or try and add enough `../`’s to navigate to the correct path. Or put
dummy.pdf
into a resources dir that matches the class package.