I'm developing a game in Java, but I'm having trouble executing it as a JAR file. Everything works fine when running it from Eclipse, but once it's exported to .JAR, no images load. I've searched many similar questions, and this seems to be a common problem, however none of the answers has helped me.
In the Eclipse project, I have two build paths: src - which constains all the .java -, and resources - which contains a subfolder named images, which has the two images I need. The method I'm using is
public void loadContent()
{
try
{
backgroundImg = ImageIO.read(getClass().getResource("/images/background.jpg"));
}
catch (IOException e)
{
e.getStackTrace();
}
}
, being backgroundImg an object of BufferedImage
I've tried all combinations involving getResourceAsStream() instead of getResource(), "images..." instead of "/images..." and many other...
The resources are being added to the JAR, it's just that I can't load them. Does anybody know how to solve it?
Thanks in advance!