I have a problem which I can't find much help for on google. My project is a Maven project. For those unfamiliar, the Maven project structure is basically this:
Java code is placed in the java folder and resources (such as images) are placed in the resource folder.src/main/java
src/main/resources
...
We have several files, which are in the resource directory, such as:
Now, when you package the project into a jar, the file structure changes a bit:src/main/resources/SpriteMap.xml
src/main/resources/images/spriteImages.xml
src/main/resources/images/character/player/headmovements.jpg
...
You'll notice the src/main no longer exists.resources/SpriteMap.xml
resources/images/spriteImages.xml
resources/images/characters/player/headmovements.jpg
So, to access a resource within a jar, I use the code:
That same line of code does NOT work within my IDE (Eclipse). Within Eclipse, it sets stream to null, which then throws a null pointer later on for obvious reasons. Based on what I've read online, the reason is because that first slash is supposed to take you to the resource root. However, the resource root is different in Eclipse than it is in a Jar (src/main does not exist in the Jar), so it just doesn't work.URL stream = getClass().getResource("/resources/SpriteMap.xml");
While I can find a lot of stuff from people saying what the problem is, I have been unable to find an actual solution. Does anyone have any ideas?