Having trouble getting default config resource [SOLVED]

Hey all,

I’ve been trying to access a file in my plugin.jar which acts as a static .conf template.
These are the things I’ve tried:

-this.getClass().getClassLoader().getResource(“String”);
where string has been:
-“geoworld.conf”
-"/geoworld.conf"
-"…/geoworld.conf"
-"…/…/geoworld.conf"

This is my file structure:
[spoilers]https://scontent.fsnc1-1.fna.fbcdn.net/hphotos-xtp1/v/t34.0-12/12584174_10208445013784064_1325376911_n.jpg?oh=3453497b64fee8df2896895b4a532a99&oe=56AA9AB0
[spoilers]https://scontent.fsnc1-1.fna.fbcdn.net/hphotos-xpt1/v/l/t34.0-12/12648045_10208445013624060_995863142_n.jpg?oh=794ee9dd536946a928f33a5aecf302c0&oe=56AA4811

and this is the current code:
[spoilers/]https://github.com/El-minadero/GeoWorld/blob/master/GeoCraft/src/main/java/com/geoworld/MainDefaults.java#L82

If you open up the jar file once it’s created (eg using 7zip) can you see the resource file in there? If not you may not be creating the jar properly.

Unzipping the jar file does indeed reveal a resource folder which contains my default.conf file, as well as a com folder where all the packages are located in.

And there’s your problem.

It looks like you’re using your IDE’s build tool rather than gradle/maven. Both gradle/maven will put files in the resources folder into the root of the jar, not a subdirectory.

Most tutorials expect this, and so reference the file name directly with no folder. So you can either modify your IDE to not create a subdirectory, or you can reference it using getResource("resources/geoworld.conf").

Perfect!

That solved it.