0

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... folder

Also here's how I'm building my jar

artifact

Community
  • 1
  • 1
java
  • 1,319
  • 6
  • 15
  • 30
  • Make sure that the /resources contents are added to the JAR. Are you using the Maven Shade plug-in to create your fat JAR with all the dependencies inside? You should be. Open the JAR and see if that file is inside. If it's not, you have a packaging problem. – duffymo Aug 08 '17 at 17:57
  • See http://stackoverflow.com/a/42200519/104891. Unpack the jar and see what's inside. – CrazyCoder Aug 08 '17 at 17:59
  • I have unpacked the jar, there is no resource folder – java Aug 08 '17 at 18:00
  • @java file a bug at https://youtrack.jetbrains.com/issues/IDEA and attach a sample project to reproduce. – CrazyCoder Aug 08 '17 at 18:45

0 Answers0