How do you properly build a jar with libgdx?

Hey,

I finally finished making up a little test game while going through the libgdx tutorials and I want to build the jar file so I can show it to one of my friends. I’ve tried doing this a few different ways at this point but the jar never runs. I’ve tried exporting as a jar and as an executable jar with various different options selected, I’ve also tried running it with the required libgdx libraries within the jar, outside of the jar and with the assets folder within and outside of the jar but nothing works.

The game runs properly when running it from eclipse and I’ve made sure that there are no errors coming from any of the classes before building the jar so I’m not sure what’s up.

Edit: BTW, I’m only using libgdx for desktop; I don’t care about android, mac or whatever else there was.

Eclipse, project properties, build path, export, check em all.

Have you tried fat jar? It is the easiest way to bundle jar and guaranteed to work.

I just tried both fat jar and checking everything but neither of those worked either. The assets folder is also never included in the jar so I’ve had to keep manually adding it after the jar is created. Prom is today so I probably won’t get to reply again tonight; below is a link to download my project folder, maybe I’m just exporting this wrong?

http://www.mediafire.com/download/4quc57ud5pzakkq/Project_01.rar

I would like to know the solution to this to. I Don’t know how to pack the resources into the jar file and I’m guessing that is the problem.

When I export my libgdx projects (and they work fine when I do) is right click the desktop project -> export -> select runnable jar file click next -> Select proper launch configuration and export destination. Also make sure packag required libraries into generated jar is selected. Then click finish. This seems to work great for me…

Like wreed said, choose Runnable jar export, not the normal one. It will add the manifest greatly. For assets, check project properties if it’s included as part of exporting.

I’ve done that before, but its working this time. I don’t know what i did differently.

Just tried that, it didn’t work. =/

You are storing all assets in the android project assets folder right?

No; they’re all in the assets folder under the project folder. I followed this ( http://www.java-gaming.org/topics/libgdx-how-do-i-load-local-assets-without-an-android-project/29148/msg/266799/view.html#msg266799 ) guide so that I wouldn’t need to deal with all that android, linux and mac stuff. I’m only testing on desktop so the rest didn’t matter.

It matters in this situation :wink: Sometimes the default way makes things easy

Then how do I fix all this junk? It shouldn’t need a bunch of useless project folders just to compile and run for desktop.

Hey, im not saying this is the best solution im just saying its a solution

I just went in to poke around at my code a bit after not looking at it for a few days. It ends up that the crashing was caused by Eclipse not putting the assets folder into the jar but rather putting the assets in directly; the code required them to be within an “assets” folder. After that the program started opening and crashing right away so I poked around a bit more and found that it was crashing because the “Save.txt” file wasn’t being created for it to save data into.

Everything works now!