title: Accessing resources on classpath using parent folder sign (../)
body: <p>I am trying to access resource on classpath using <code>getResourceAsStream()</code>:</p>
  
  <pre><code>InputStream is = getClass().getResourceAsStream(path);
  </code></pre>
  
  <p>If path is something like this: <code>/net/original/xsdtestxml.xml</code>, then I have no problems.
  However, I have situations where I must use "go to parent" sign <code>../</code> to access certain files. I am constructing path manually based on certain parameters.</p>
  
  <p>Final result is something like this:</p>
  
  <pre><code>/net/original/../original/xsdtestxml.xml
  </code></pre>
  
  <p>This works fine in Eclipse. It works fine when I run it outside of Eclipse (from command line in programs target folder where .class are contained). However, as soon as I pack those in jar file, it throws <code>NullPointerException</code>.</p>
  
  <p>Is there a possibility for <code>getResourceAsStream()</code> to support such a format after exported to jar? If not, is there a Java/ Utility class that can get file path without <code>../</code> signs? For example to convert <code>/net/original/../original/xsdtestxml.xml</code> to <code>/net/original/xsdtestxml.xml</code> format?</p>
  
  <p><strong>One possible solution:</strong></p>
  
  <p>There is a <code>URI</code> class found in <code>java.net</code> package that does what I need. You simply create <code>URI</code> object with constructor or use static <code>create(String)</code> method. Then you call <code>normalize()</code> method and can get string path using <code>toString()</code> or <code>getPath()</code> methods.</p>
  
  <p>Here is the example of code that worked for me:</p>
  
  <pre><code>String finalPath = URI.create(inputPath).normalize().getPath();
  </code></pre>
  
  <p><code>inputPath</code> is path that can contain <code>../</code> literals.
  This perfectly converts <code>/net/original/../original/xsdtestxml.xml</code> to <code>/net/original/xsdtestxml.xml</code> which is just what I needed to access file from jar on classpath.</p>