2

The Problem

I am loading a yaml-configuration in a Minecraft-Server plugin, but it can't find the file / returns null. I tried everything.

I checked if the file also exists in the jar-file and renamed the file to game_settings.yml.txt, too, but with no success.

My package structure

+- src [resource root]
  +- my.package
    +- MyClass.java
    +- game_settings.yml

What I tried

this.getClass().getResourceAsStream("game_settings.yml"); // null
MyClass.class.getResourceAsStream("game_settings.yml"); // null
MyClass.class.getClass().getResourceAsStream("game_settings.yml"); // null
this.getClass().getClassLoader().getResourceAsStream("game_settings.yml"); // null

The weird thing is that when I use getResource(), it always finds the path. So Java actually knows that the file is there.

EDIT: The file is not found in the package, but I can see it in the jar. Why is the file invisible for Java?

Sources

B. Colin Tim
  • 293
  • 5
  • 13
  • Can you check by pitting yaml file in the resource root? – Chathura Buddhika Jun 29 '17 at 13:59
  • `getResource()` and `getResourceAsStream()` require different types of paths, as you have found out. I think you have found out that *guessing* is not a valid debugging technique either. Reading the actual documentation and using a step-debugger are valid techniquest. –  Jun 29 '17 at 14:03
  • [What does your step debugger tell you?](http://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) –  Jun 29 '17 at 14:06
  • The problem is, that you can't use a step debugger because of Bukkit: https://bukkit.org/. It has just a logger, where I have to log for debugging. With the solution of https://stackoverflow.com/questions/16563622/reading-txt-file-from-jar-fails-but-reading-image-works, I can get more detail, like FileNotFound. – B. Colin Tim Jun 29 '17 at 14:20
  • Now, the Plugins tells me that the file cannot be found but, as shown above, the file is in the jar-file. – B. Colin Tim Jun 29 '17 at 15:48
  • I got a solution! It seems that _**Bukkit** doesn't reload all resources_ with the command `/reload`. When I **completely restart the server**, it will find the file. – B. Colin Tim Jun 30 '17 at 14:52

0 Answers0