Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to package resources, that are accessed directly , into a jar file

I have recently developed a game in Slick2D, i have accessed all my images directly e.g

Image i = new Image("address.png");

as opposed to using a class that will load resources or using an input stream.

I wondered if it would still be possible to load all the resources into a jar, i added the /res folder to my buildpath and used jarsplice to add my libraries and natives however the jar will not run because it cannot find the images.

like image 577
Josh Jackson Avatar asked Dec 06 '25 01:12

Josh Jackson


1 Answers

Image i = new Image("address.png");

Is looking into the root filesystem where your application is running. If you want to use the resources packed in your jarfile you must do:

Image i = new Image(getClass().getResource("/res/address.png").toURI()); // In case your Image object accepts URI as parameters

EDIT

Image i = new Image(getClass().getResource("/res/address.png").toExternalForm()); // Since your object only accept Strings
like image 126
Bruno Vieira Avatar answered Dec 08 '25 14:12

Bruno Vieira