title: Eclipse and Maven - resources in jar
body: <p>I know this question was asked many times before, but I still can't manage it to work.
  What I want to achieve is to create jar which will load resource (packed in jar) in runtime, without broking resource loading while executing application from Eclipse.</p>
  
  <p>My project structure is standard:</p>
  
  <pre><code>src/main/java
  src/main/resources
  src/test/java
  src/test/resources
  </code></pre>
  
  <p>Code for load image resource:</p>
  
  <pre><code>        ClassLoader classLoader = getClass().getClassLoader();
          splashImage = ImageIO.read(new File(classLoader.getResource("img/splash.png").getFile()));
  </code></pre>
  
  <p>It is working fine when starting the App from the Eclipse. However, when I export the runnable jar from the Eclipse, it doesn't works.</p>
  
  <p>Exported jar have /resources/img folder in it's root directory. But when the app starts, an exception is thrown:</p>
  
  <pre><code>Caused by: javax.imageio.IIOException: Can't read input file!
  </code></pre>
  
  <p>How it is possible to make it work from runnable jar file and when running the App from the Eclipse?</p>
  
  <p>I was also trying to build jar with maven plugins, but with no luck.</p>
  
  <pre><code> &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.1&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;source&gt;1.7&lt;/source&gt;
                  &lt;target&gt;1.7&lt;/target&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
              &lt;version&gt;2.8&lt;/version&gt;
              &lt;executions&gt;
                  &lt;execution&gt;
                      &lt;id&gt;copy-dependencies&lt;/id&gt;
                      &lt;phase&gt;package&lt;/phase&gt;
                      &lt;goals&gt;
                          &lt;goal&gt;copy-dependencies&lt;/goal&gt;
                      &lt;/goals&gt;
                      &lt;configuration&gt;
                          &lt;outputDirectory&gt;${project.build.directory}/lib&lt;/outputDirectory&gt;
                      &lt;/configuration&gt;
                  &lt;/execution&gt;
              &lt;/executions&gt;
          &lt;/plugin&gt;
          &lt;plugin&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;foo.bar.App&lt;/mainClass&gt;
                      &lt;/manifest&gt;
                  &lt;/archive&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>