title: getResource returning NullPointerException
body: <p>I'm trying to get two resource files called <code>config.yml</code> and <code>messages.yml</code>, but it's not working. I made a project to test with just a file called <code>text.txt</code> located in <code>resources/files/test.txt</code>.</p>
  
  <p>Like this:<br>
  <a href="https://i.stack.imgur.com/7QH4D.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7QH4D.png" alt="enter image description here"></a></p>
  
  <p>My code is:</p>
  
  <pre><code>package be.isach.tests;
  
  import java.io.File;
  
  public class Test {
  
      public static void main(String[] args) {
          Test obj = new Test();
          for(File file : obj.getFile("files/").listFiles())
              System.out.println(file.getName());
      }
  
      private File getFile(String fileName) {
          ClassLoader classLoader = getClass().getClassLoader();
          return new File(classLoader.getResource(fileName).getFile());
      }
  
  }
  </code></pre>
  
  <p>When I run it from my IDE (IntelliJ IDEA), it runs well and prints:
  "test.txt".</p>
  
  <p>But when I run it in the compiled jar, built with "gradle build", it just doesn't work, and returns a NPE:</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
          at be.isach.tests.Test.main(Test.java:12)
  </code></pre>
  
  <p>Here's my <code>build.gradle</code> (external link not to have a too big question post) if it can help fixing all that:
    <a href="http://pastebin.com/gY4NPx8t" rel="nofollow noreferrer">http://pastebin.com/gY4NPx8t</a></p>
  
  <p>I tried a lot of things, such as; <code>Thread.currentThread()</code> and more. I searched for over 2 hours on the internet, but have found nothing that actually works.</p>
  
  <p>If you're wondering, yes, it puts resources in the Jar:
  I can't put any more links.</p>
  
  <p>Thanks in advance,
  Sacha.</p>