Adding folders to a Jar
I have an application that uses images stored in the folder "images" that is at the root of the project. I want to export my application into a jar file and I want that jar file to contain the images folder within it. How to do this using Netbeans IDE?
Also how should I declare my Image objects? Right now I am doing this :
Image img = Toolkit.getDefaultToolkit().getImage("images/" + fileName);
But apperantly this code won't work if the images are to be read from within a Jar. I am looking for the correct way to do it.
Thanks in advance.
Stick the images folder under Source Packages in your Netbeans project and use getResourceAsStream() to get a stream to that resource as an InputStream. I can never remember whether the path has to start with a "/" or not...I always end up having to experiment!
Your url is null, implying that that path isn't correct.
Try it with a '/' at the start.
As I say, I can never remember whether it needs a '/' or not...:)