https://kotlinlang.org logo
Title
f

FunkyMuse

02/05/2023, 6:00 PM
hey guys, is it possible to access
resources
folder via
java.io.File
when I run the app locally it works, but when I build the fatJar, this Folder is not available and an exception is thrown, what I’m doing wrong?
private val tempMailDirectory = Paths.get("").toAbsolutePath().toString() + "/src/main/resources/blacklisted_domains"
m

Mustafa Ozhan

02/05/2023, 6:04 PM
I think you do not need even
java.io.File
I have in my backend like this
javaClass.classLoader?.getResource("YOUR_PATH")?.readText()?.let{
// do your stuff
}
f

FunkyMuse

02/05/2023, 6:56 PM
@Mustafa Ozhan thank you, that solves the problem, kinda hacky way but it works
c

Chrimaeon

02/05/2023, 7:14 PM
That’s not a hacky way - that’s the way you access resourses in a jar package 😉 https://docs.oracle.com/javase/8/docs/technotes/guides/lang/resources.html
if you need a
File
you can use the
URL
retuned from
ClassLoader#getResource(String name)
f

FunkyMuse

02/05/2023, 7:25 PM
TIL @Chrimaeon thanks