title: Building an executable jar with Maven, Eclipse
body: <p>End goal is I am trying to build an executable jar in eclipse with maven, that's packaged with its dependencies like so. The end file structure I'm trying to accomplish is the following..</p>
  
  <pre><code>/target/my-distributable.zip
          |- lib (all third party jar's, which I have loaded through maven)
          |- images (the images my swing app can reference)
          |- my-application.jar (my executable jar, manifiest within with correct classpath references)
          |- my-application.properties (the properties my app reads and can modify)
          |- READ-ME.TXT
  </code></pre>
  
  <p>From here the end user would be able to unzip the distributable zip file, double click on the jar to start a java swing application which has dependencies located in the /lib directory. And there's a text editor in/as part of the swing app that I'd like to have reference images from the /images directory. What I would like to accomplish is having maven create a zip file which contains everything in this /dist folder, including my executable jar and it's dependencies located in a lib directory.</p>
  
  <p>I know I need to have my exec jar's manifest include the Main class from which to run the application, and include the lib and images directory on the classpath of the manifest as well as my properties file.</p>
  
  <p>I have tried several combinations of the maven shade plugin which seems to throw everything in one jar (not useful here as I need the zip with my exec jar inside, and lib outside the exec jar), and maven-assembly-plugin.</p>
  
  <h2>Here is my current POM with dependencies..</h2>
  
  <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.kiosk&lt;/groupId&gt;
    &lt;artifactId&gt;kiosk-application&lt;/artifactId&gt;
    &lt;version&gt;2.1&lt;/version&gt;
  
    &lt;name&gt;Kiosk Application&lt;/name&gt;
  
      &lt;properties&gt;
          &lt;jdk.version&gt;1.5&lt;/jdk.version&gt;
      &lt;/properties&gt;
  
    &lt;dependencies&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;commons-beanutils&lt;/groupId&gt;
          &lt;artifactId&gt;commons-beanutils&lt;/artifactId&gt;
          &lt;version&gt;1.9.1&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;commons-configuration&lt;/groupId&gt;
          &lt;artifactId&gt;commons-configuration&lt;/artifactId&gt;
          &lt;version&gt;1.10&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;commons-io&lt;/groupId&gt;
          &lt;artifactId&gt;commons-io&lt;/artifactId&gt;
          &lt;version&gt;2.4&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;commons-jxpath&lt;/groupId&gt;
          &lt;artifactId&gt;commons-jxpath&lt;/artifactId&gt;
          &lt;version&gt;1.3&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;net.sf.ezmorph&lt;/groupId&gt;
          &lt;artifactId&gt;ezmorph&lt;/artifactId&gt;
          &lt;version&gt;1.0.6&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.itextpdf&lt;/groupId&gt;
          &lt;artifactId&gt;itextpdf&lt;/artifactId&gt;
          &lt;version&gt;5.5.0&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.miglayout&lt;/groupId&gt;
          &lt;artifactId&gt;miglayout&lt;/artifactId&gt;
          &lt;version&gt;3.7.4&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.shef&lt;/groupId&gt;
          &lt;artifactId&gt;shef&lt;/artifactId&gt;
          &lt;version&gt;1.0&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;net.sf.json-lib&lt;/groupId&gt;
          &lt;artifactId&gt;json-lib&lt;/artifactId&gt;
          &lt;version&gt;2.2.2&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.novaworx.syntax&lt;/groupId&gt;
          &lt;artifactId&gt;novaworx-syntax&lt;/artifactId&gt;
          &lt;version&gt;0.0.7&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;sam.i.am&lt;/groupId&gt;
          &lt;artifactId&gt;sam-i-am&lt;/artifactId&gt;
          &lt;version&gt;1.0&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;jtidy.me&lt;/groupId&gt;
          &lt;artifactId&gt;jtidy-8&lt;/artifactId&gt;
          &lt;version&gt;8.0&lt;/version&gt;
      &lt;/dependency&gt;
  
    &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>And this is my last attempt with using the maven-assembly-plugin adding to the pom above..</p>
  
  <pre><code>  &lt;build&gt;
  
      &lt;pluginManagement&gt;
        &lt;plugins&gt;
          &lt;plugin&gt;
            &lt;groupId&gt;org.eclipse.m2e&lt;/groupId&gt;
            &lt;artifactId&gt;lifecycle-mapping&lt;/artifactId&gt;
            &lt;version&gt;1.0.0&lt;/version&gt;
            &lt;configuration&gt;
              &lt;lifecycleMappingMetadata&gt;
                &lt;pluginExecutions&gt;
                  &lt;pluginExecution&gt;
                    &lt;pluginExecutionFilter&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
                      &lt;versionRange&gt;[2.0,)&lt;/versionRange&gt;
                      &lt;goals&gt;
                        &lt;goal&gt;copy-dependencies&lt;/goal&gt;
                      &lt;/goals&gt;
                    &lt;/pluginExecutionFilter&gt;
                    &lt;action&gt;
                      &lt;execute /&gt;
                    &lt;/action&gt;
                  &lt;/pluginExecution&gt;
                &lt;/pluginExecutions&gt;
              &lt;/lifecycleMappingMetadata&gt;
            &lt;/configuration&gt;
          &lt;/plugin&gt;
        &lt;/plugins&gt;
      &lt;/pluginManagement&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.5&lt;/source&gt;
                    &lt;target&gt;1.5&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}/libs&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;addMavenDescriptor&gt;false&lt;/addMavenDescriptor&gt;
                          &lt;compress&gt;true&lt;/compress&gt;
                          &lt;manifest&gt;
                              &lt;addClasspath&gt;true&lt;/addClasspath&gt;
                              &lt;classpathPrefix&gt;libs/&lt;/classpathPrefix&gt;
                              &lt;mainClass&gt;com.kiosk.app.KioskApplication&lt;/mainClass&gt;
                          &lt;/manifest&gt;
                      &lt;/archive&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
  
  
  
             &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.2.1&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;descriptors&gt;
                          &lt;descriptor&gt;/src/main/assembly/assembly.xml&lt;/descriptor&gt;
                      &lt;/descriptors&gt;
                      &lt;finalName&gt;kiosk-application_${project.version}&lt;/finalName&gt;
                      &lt;outputDirectory&gt;${project.build.directory}/dist&lt;/outputDirectory&gt;
                      &lt;workDirectory&gt;${project.build.directory}/assembly/work&lt;/workDirectory&gt;
                  &lt;/configuration&gt;
                  &lt;executions&gt;
                      &lt;execution&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>And my</p>
  
  <h2>assembly.xml</h2>
  
  <pre><code>&lt;assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"&gt;
      &lt;id&gt;bundle&lt;/id&gt;
      &lt;formats&gt;
          &lt;format&gt;jar&lt;/format&gt;
      &lt;/formats&gt;
      &lt;filesets&gt;
          &lt;fileset&gt;
              &lt;directory&gt;target&lt;/directory&gt;
              &lt;outputDirectory&gt;&lt;/outputDirectory&gt;
              &lt;includes&gt;
                  &lt;include&gt;*.jar&lt;/include&gt;
              &lt;/includes&gt;
          &lt;/fileset&gt;
          &lt;fileset&gt;
              &lt;directory&gt;target/libs&lt;/directory&gt;
              &lt;outputDirectory&gt;libs&lt;/outputDirectory&gt;
              &lt;includes&gt;
                  &lt;include&gt;*.jar&lt;/include&gt;
              &lt;/includes&gt;
          &lt;/fileset&gt;
      &lt;/filesets&gt;
  &lt;/assembly&gt;
  </code></pre>
  
  <p>My application structure..</p>
  
  <pre><code>/src
   |- main
      |- assembly
      |- java
         |- com
            |- kiosk
               |- etc....
      |- resources
         |- myImage.jpg
         |- my-application.properties
  </code></pre>
  
  <p>When I try to use the pom above with the build section using the maven-assembly-plugin I'm currently getting the error..</p>
  
  <p>Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2.1:single (default) on project kiosk-application: Error reading assemblies: Error reading descriptor: /src/main/assembly/assembly.xml: Unrecognised tag: 'filesets' (position: START_TAG seen ...\r\n    ... @8:15) -> [Help 1]</p>
  
  <p>This seems like what should be a fairly easy task to accomplish, however I have never used maven to accomplish this sort of thing and I'm having an issue orchestrating the build to produce the end result I'd like to accomplish. Is there any maven experts out there than can help point me in the right direction..? </p>