I created a game using LibGDX and I'm trying to figure out how to run a jar without having the images and such within the same folder as it. How do I make it so the jar itself is self sufficient and has the assets contained within it?
1 Answers
If you want to export standalone jar(containing all assets of your game) from desktop module.
Libgdx uses gradle for project building so Hopefully you're using gradle and IntellijIDEA or Android Studio as IDE.
Use Terminal
View -> Tool Windows-> Terminal or Alt+ F12
run command
on window
gradlew desktop:dist
on Mac
./gradlew desktop:dist
It will put all your asset from your assets folder of android module into your jar. Your can find your jar in desktop module.
Create jar with Artifact
File -> Project Structure -> Artifacts -> Add(+) -> Jar -> From module and dependencies ->
Module : desktop Main Class : DesktopLauncher
then OK
In OutputLayout tab -> Add Copy of(+) -> Directory Content -> Choose your Android Assets folder -> Apply -> Ok
Then Build -> BuildArtifacts. -> desktop.jar -> build

- 19,936
- 8
- 46
- 65