Search code examples
javaeclipselibgdxassets

Executable LibGDX Jar File doesn't load assets


My LibGDX project runs in Eclipse but when I export it to an executable JAR file I get "Couldn't load file: play_button_inactive.png" and "File not found: play_button_inactive.png (Internal)".

I refreshed and cleaned the project. I deleted my assets link in the Desktop Project and re-loaded it in the Build Path but the same errors persisted.

I looked inside the jar file and Eclipse packaged in the assets separately into the Jar file so I put them all into a new "assets" folder manually but I got the same errors when I ran it. I used the command

java -jar fileName.jar

Here is my Build Path.

Build-Path 1

Build-Path 2

Thanks for any suggestions as to what I am doing wrong.

UPDATE: After reading around I found a solution which is to put all the assets into the same directory as the jar file. Is there any way to package them into the jar file?


Solution

  • I fixed the problem by not using Eclipse's jar file building tools and used gradlew desktop:dist instead.

    This works perfectly and packages all resources and files into the generated jar file.