In eclipse, i have a project i am working on with resources that i call like this for example
URL url = FighterComponent.class.getResource("/gfx/characters/");
File file = new File(url.getPath() + info.name + "/" + frame.path);
/gfx/ being a folder inside of res. res is my resource folder which i have linked by doing this:
run > run configurations... > Classpath > Select user entries > Advanced > Add folder
My question now is that where should the res folder be after i exported my project into a runnable jar for my friends to be able to test it? I tried putting it in the same folder as my jar and inside my jar and for both the URL was null.
Any idea ?
If the name begins with a '/' ('\u002f'), then the absolute name of the resource is the portion of the name following the '/'.
So, you should have a gfx/characters directory inside the jar file. Under this directory, if you have an image.jpg resource, you will have to retrieve it using:
URL url = TheClass.class.getResource("/gfx/characters/image.jpg");
You can also use the getResourceAsStream() to get an InputStream that you can read from.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With