title: ClassLoader always returns null when called from within a jar
body: <p>I ran into library loading problems after creating a jar from my code via maven. I use intelliJ idea on Ubuntu. I broke the problem down to this situation:</p>
  
  <p>Calling the following code from within idea it prints the path correctly.</p>
  
  <pre><code>package com.myproject;
  
  public class Starter {
      public static void main(String[] args) {
          File classpathRoot = new File(Starter.class.getResource("/").getPath());
          System.out.println(classpathRoot.getPath());
      }
  }
  </code></pre>
  
  <p>Output is:</p>
  
  <pre><code>/home/ted/java/myproject/target/classes
  </code></pre>
  
  <p>When I called <code>mvn install</code> and try to run it from command line using the following command I'm getting a <code>NullPointerException</code> since <code>class.getResource()</code> returns <code>null</code>:</p>
  
  <pre><code>cd /home/ted/java/myproject/target/
  java -cp myproject-0.1-SNAPSHOT.jar com.myproject.Starter
  </code></pre>
  
  <p>same for calling:</p>
  
  <pre><code>cd /home/ted/java/myproject/target/
  java -Djava.library.path=. -cp myproject-0.1-SNAPSHOT.jar com.myproject.Starter
  </code></pre>
  
  <p>It doesn't matter if I use <code>class.getClassLoader().getRessource("")</code> instead. Same problem when accessing single files inside of the target directory instead via <code>class.getClassLoader().getRessource("file.txt")</code>.</p>
  
  <p>I want to use this way to load native files in the same directory (not from inside the jar). What's wrong with my approach?</p>