[LWJGL] How to properly load images and use them in a JAR(SOLVED)

Original Poster.

Yes you would need to put it in a zip. Though I’m sure anyone with a computer could unzip a folder and hit a file. :stuck_out_tongue: Though I understand when your packing these games off and shipping them you have to act like your consumer is a complete computer noob.

When loading resources (via getResource/getResourceAsStream), the resource is loaded via the ClassLoader. For the default implementation, this means the files need to be on the classpath. Whether you are running from within the IDE or from without is irrelevant – the classpath is all that matters. Here are two things to keep in mind for this to work both inside and outside of Eclipse.

  1. Inside Eclipse, your project’s ‘bin’ subdirectory is already on the classpath, so that’s where you want your resources. An easy way to do this is to create the resource folder as a package inside Eclipse (via “New Package”). Then you can import your images into the package.

  2. Outside Eclipse, make sure the jar containing your resources is in the same place as the jars containing your classes (if they aren’t all in the same jar).

Given the folder (package) ‘res’ and the file ‘res/foo.png’, then getResourceAsStream(“res/foo.png”) should work in both cases.

Lol you got the idea. Like my little sisters, I don’t think they understand how to even make a file

Is the jar containing the resources the first jar I make that doesn’t run. I don’t understand step 2 so well.
I’m going to look at some source code for an example but does anyone have a good visual tutorial on this? ??? ??? ??? ??? ??? ??? ??? ??? ???

I tried keeping the jar in a folder with a batch file that launches it. It still pops up and disappears giving the input stream errors :’(

Even when zipped I get the same results. Do I have o use textures in lwjgl? It’s all complicated

Launching the program from a batch file will fix nothing.

Please, you need to go find a tutorial on IO in Java.

Oops, can’t believe I posted that when it is only applicable to getResource().

You can just extract the files from the jar, put them in a temporary folder, and read them. Yeah, I know it was solved.

Did you have to remove the entire first post to say that you solved it? Next time, keep the post so that other people can come back and learn from this thread.