title: How to add resources to jar using maven shade plugin
body: <p>My Project structure has resources folder inside the src/main/ folder. The resources folder contains the file server.properties. My pom is as follows:</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      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.fde&lt;/groupId&gt;
      &lt;artifactId&gt;Listener&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;Listener&lt;/name&gt;
      &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;hibernate.version&gt;3.6.10.Final&lt;/hibernate.version&gt;
          &lt;java.version&gt;1.6&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;3.8.1&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;!-- Hibernate dependencies START --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-lang&lt;/groupId&gt;
              &lt;artifactId&gt;commons-lang&lt;/artifactId&gt;
              &lt;version&gt;2.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-ehcache&lt;/artifactId&gt;
              &lt;version&gt;${hibernate.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
              &lt;version&gt;${hibernate.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javassist&lt;/groupId&gt;
              &lt;artifactId&gt;javassist&lt;/artifactId&gt;
              &lt;version&gt;3.12.1.GA&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-collections&lt;/groupId&gt;
              &lt;artifactId&gt;commons-collections&lt;/artifactId&gt;
              &lt;version&gt;3.2.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;version&gt;5.1.9&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- Hibernate dependencies END --&gt;
      &lt;/dependencies&gt;
      &lt;build&gt;
          &lt;sourceDirectory&gt;src/main/java&lt;/sourceDirectory&gt;
          &lt;resources&gt;
              &lt;resource&gt;
                  &lt;directory&gt;resources&lt;/directory&gt;
              &lt;/resource&gt;
          &lt;/resources&gt;
          &lt;testSourceDirectory&gt;src/test/java&lt;/testSourceDirectory&gt;
  
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-shade-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.2&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;phase&gt;package&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;shade&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;transformers&gt;
                                  &lt;transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"&gt;
                                      &lt;mainClass&gt;com.fde.ListenerServer&lt;/mainClass&gt;
                                  &lt;/transformer&gt;
                                  &lt;transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer"&gt;
                                      &lt;resource&gt;resources&lt;/resource&gt;
                                      &lt;file&gt;server.properties&lt;/file&gt;
                                  &lt;/transformer&gt;
                              &lt;/transformers&gt;
                              &lt;artifactSet&gt;
                                  &lt;excludes&gt;
  
                                      &lt;exclude&gt;junit:junit&lt;/exclude&gt;
  
                                  &lt;/excludes&gt;
                              &lt;/artifactSet&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
  
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>The Jar is created properly and the main class is mentioned in the manifest. I have the following questions :</p>
  
  <ol>
  <li><p>The target folder contains the classes folder whch has the class files. The jar also contains them so why are they needed. My goal is to have a executable jar with all the dependancies only.</p></li>
  <li><p>The resources are not getting added in the jar at all. I have added the transformer according to instructions seen on the net but no use!!!</p></li>
  <li><p>What are the other dir getting created in the target folder (maven-archiver, surefire, surefire-reports etc) ??</p></li>
  <li><p>Another jar gets created every time i do a maven clean install (original-Listener....jar)</p></li>
  </ol>
  
  <p>I have absolutely no clue about how to include resources. Any help is appreciated!!</p>
  
  <p>EDIT:::</p>
  
  <p>This is the tag i used for the maven-assembly-plugin:</p>
  
  <pre><code> &lt;plugin&gt;
      &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
      &lt;executions&gt;
        &lt;execution&gt;
          &lt;phase&gt;package&lt;/phase&gt;
          &lt;goals&gt;
            &lt;goal&gt;attached&lt;/goal&gt;
          &lt;/goals&gt;
        &lt;/execution&gt;
      &lt;/executions&gt;
      &lt;configuration&gt;
      &lt;archive&gt;
              &lt;manifest&gt;
                &lt;mainClass&gt;com.fde.ListenerServer&lt;/mainClass&gt;
              &lt;/manifest&gt;
            &lt;/archive&gt;
        &lt;descriptorRefs&gt;
          &lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt;
        &lt;/descriptorRefs&gt;
      &lt;/configuration&gt;
    &lt;/plugin&gt;
  </code></pre>
  
  <p>This created the Listener-1.0-SNAPSHOT-jar-with-dependencies.jar with all the classes from referred jars in the folders. The manifest also contains the main class. </p>
  
  <p>The problem still is that I cant include the resource bundle in the folder \src\main\resources.</p>
  
  <p>Also I cant understand why jar files referenced from my code are included in the jar as well as inside the META-INF folder. </p>