karelpeeters
09/15/2018, 6:28 PMresource
folder (it's not a package) and Class.getResource().
Usually the build tool (gradle, maven, InteliJ, ...) is configured so that it maps both the src
and resource
folders to the same directories at runtime, concretely this means that if you have src/mypackage/Test.Kt
and resources/mypackage/test.txt
the actual jar you build will have mypackage/Test.class
and mypackage/test.txt
. The src
and resource
folders don't exist at runtime, so they're not relevant for getting resources. (All assuming your build tool in configured correctly of course)
Second part, MyClass.javaClass.getResource('mypackage/test.txt')
looks for test.txt
in the package mypackage
, but relative to the package of MyClass
. So if MyClass
is already in mypackage
, you should just use MyClass.javaClass.getResource('test.txt')`.