title: Read config file outside jar
body: <p>I am trying to create jar where I can read a config file outside the jar file. Preferably from the directory where the jar file is located. My directory structure is as follows:</p>
  
  <pre><code>/src/main/resources/config
  </code></pre>
  
  <p>I have a maven project that I run mvn install on to create a jar file.</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;plugin&gt;
              &lt;!-- Build an executable JAR --&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.4&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;archive&gt;
                      &lt;manifest&gt;
                          &lt;addClasspath&gt;true&lt;/addClasspath&gt;
                          &lt;classpathPrefix&gt;lib/&lt;/classpathPrefix&gt;
                          &lt;mainClass&gt;com.expedia.e3.qm.perforce.audit.Main&lt;/mainClass&gt;
                      &lt;/manifest&gt;
                      &lt;manifestEntries&gt;
                          &lt;Class-Path&gt;config/config.xml&lt;/Class-Path&gt;
                      &lt;/manifestEntries&gt;
                  &lt;/archive&gt;
                  &lt;excludes&gt;
                      &lt;exclude&gt;**/config/&lt;/exclude&gt;
                  &lt;/excludes&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
  </code></pre>
  
  <p>Right now I am manually moving my config folder from /target/classes/config to /target/config I have researched the maven assembly plugin however I have tried all the different configurations of it and I was unable to get it to output only to /target/config it would always output /target/audit-1.0/config where audit-1.0 is my maven project name. </p>
  
  <p>I am using Intellij IDEA to debug my program and to build/install the maven project. </p>
  
  <p>In code I am trying to access the file via </p>
  
  <pre><code>InputStream stream = Class.class.getResourceAsStream("/config/config.xml");
  </code></pre>
  
  <p>Which works when I run it in the IDE however when I run it from the command line:</p>
  
  <pre><code>java -jar ./audit-1.0.jar
  </code></pre>
  
  <p>It throws an error after trying to access "inputStream":</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
  </code></pre>
  
  <p>I understand that "/config/config.xml" should point to "/target/audit-1.0.jar!/config/config.xml". However, I would like it to point to "/target/config/config.xml"</p>
  
  <p>Any ideas? Is this even possible?</p>