I am building a desktop app for windows using comp...
# multiplatform
f
I am building a desktop app for windows using compose multiplatform. I have a .txt file i use as a resource. I would like to build a .exe file with the .txt file embedded in it, so that users only need the .exe file to run the application. To access the text file I am using:
val resourcesDir = File(System.getProperty("compose.application.resources.dir"))
val plainText = resourcesDir.resolve("csv\\countries.csv").readLines()
The structure of the project: /composeApp ├── resources │ ├── common │ │ ├── csv │ │ │ ├── countries.csv ├── src │ ├── desktopMain │ │ ├── kotlin │ │ │ ├── repository │ │ │ │ ├── data │ │ │ │ │ ├── CountriesAndContinents.kt When building with ./gradlew packageDistributionForCurrentOS i get an executable but it also generates app and runtime folders. I tried building a .jar and packaging it with launch4j, but the generated .exe cannot find the resource file. I tried with:
javaClass.getResource("composeApp/resources/csv/countries.csv")
javaClass.getResource("/compose/application/resources/csv/countries.csv")
But both calls return null.
e
if you put it into
src/desktopMain/resources/your/package/name/csv/countries.csv
, you can access it with `your.package.name.AnyClass.getResource("csv/countries.csv")`/`.getResourceAsStream()`
f
@ephemient Thanks, this worked!
o
@fishy fish it’s @ephemient 👆🏼 not @Oluwafemi Ogundipe
f
My bad, corrected 🙂