title: Java properties file in jar not found when running jar
body: <p>When I run <code>main()</code> from IntelliJ I got as, expected <code>peter,johnson</code> as result in standard out. But when I run <code>mvn clean package</code> and try to execute <code>java -jar target/example-1.0.0-SNAPSHOT-jar-with-dependencies.jar</code> I get following error message. Why and how can I make sure that .properties file is read?</p>
  
  <pre><code>java -jar target/example-1.0.0-SNAPSHOT-jar-with-dependencies.jar
  Exception in thread "main" java.io.FileNotFoundException:      file:/Users/ismar.slomic/src/ADOP/example/target/example-1.0.0-SNAPSHOT-  jar-with-dependencies.jar!/my-example.properties (No such file or   directory)
  at java.io.FileInputStream.open0(Native Method)
  at java.io.FileInputStream.open(FileInputStream.java:195)
  at java.io.FileInputStream.&lt;init&gt;(FileInputStream.java:138)
  at java.io.FileInputStream.&lt;init&gt;(FileInputStream.java:93)
  at com.example.MyPropertiesClass.getFullName(MyPropertiesClass.java:18)
  at com.example.MyMainClass.main(MyMainClass.java:9)
  </code></pre>
  
  <p><strong>MyMainClass</strong></p>
  
  <pre><code>package com.example;
  
  import java.io.IOException;
  
  public class MyMainClass {
  
     public static void main(String[] args) throws IOException {
         MyPropertiesClass mpc = new MyPropertiesClass();
         System.out.println(mpc.getFullName());
     }
  }
  </code></pre>
  
  <p><strong>MyPropertiesClass</strong></p>
  
  <pre><code>package com.example;
  
  import java.io.BufferedInputStream;
  import java.io.FileInputStream;
  import java.io.IOException;
  import java.util.Properties;
  
  public class MyPropertiesClass {
  
    public String getFullName() throws IOException {
      Properties properties = new Properties();
      ClassLoader cl = this.getClass().getClassLoader();
      String filePath = cl.getResource("my-example.properties").getFile();
  
      BufferedInputStream bis = new BufferedInputStream(new FileInputStream(filePath));
      properties.load(bis);
  
      String name = properties.getProperty("name");
      String lastname = properties.getProperty("lastname");
      return name + "," + lastname;
    }
  }
  </code></pre>
  
  <p><strong>my-example.properties</strong></p>
  
  <pre><code>name=peter
  lastname=johnson
  </code></pre>
  
  <p><strong>pom.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://maven.apache.org/POM/4.0.0"
       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;com.example&lt;/groupId&gt;
  &lt;artifactId&gt;example&lt;/artifactId&gt;
  &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
  
  &lt;name&gt;${project.artifactId}&lt;/name&gt;
  &lt;description&gt;My Example&lt;/description&gt;
  
  &lt;properties&gt;
      &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
      &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
  &lt;/properties&gt;
  
  &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.0.0&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;descriptorRefs&gt;
                      &lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt;
                  &lt;/descriptorRefs&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.example.MyMainClass&lt;/mainClass&gt;
                      &lt;/manifest&gt;
                  &lt;/archive&gt;
              &lt;/configuration&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;id&gt;make-assembly&lt;/id&gt;
                      &lt;phase&gt;package&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;single&lt;/goal&gt;
                      &lt;/goals&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p></p>