When I run it in Intellij it works fine but when I try to build it into a jar the resource folder is not added to the jar.
I wrote some code to test if I was getting the path wrong...
String file = File.separator + "resources" + File.separator + "components" + File.separator + "game_window.png";
while (!file.isEmpty()) {
System.out.println(file + ": " + ScreenShot.class.getClassLoader().getResourceAsStream(file));
file = file.substring(1);
}
gameWindow = ImageIO.read(ScreenShot.class.getClassLoader().getResourceAsStream("components" + File.separator + "game_window.png"));
which produces the following output in Intellij:
\resources\components\game_window.png: null
resources\components\game_window.png: null
esources\components\game_window.png: null
sources\components\game_window.png: null
ources\components\game_window.png: null
urces\components\game_window.png: null
rces\components\game_window.png: null
ces\components\game_window.png: null
es\components\game_window.png: null
s\components\game_window.png: null
\components\game_window.png: java.io.BufferedInputStream@723279cf
components\game_window.png: java.io.BufferedInputStream@10f87f48
ect...
while if I run the same code in the jar it produces the following:
\resources\components\game_window.png: null
resources\components\game_window.png: null
esources\components\game_window.png: null
sources\components\game_window.png: null
ources\components\game_window.png: null
urces\components\game_window.png: null
rces\components\game_window.png: null
ces\components\game_window.png: null
es\components\game_window.png: null
s\components\game_window.png: null
\components\game_window.png: null
components\game_window.png: null
ect...
I am fairly certain the issue is that the resource folder is not being added to the jar.
I am not sure what to do as I have already marked the folder as a resource root...
Also here's how I'm building my jar