title: Generate a runnable jar and include libraries in it with Maven
body: <p>I'm trying to compile a Java project with Maven and Eclipse but I tried a lot of solutions seen on the web but none of them seem to work. I just want to build the application, create a runnable jar and include the needed libraries. I tried maven-dependency or maven-assembly but I surely miss something because I fail every time.</p>
  
  <p>Here is my pom.xml, is it ok or does it miss something?</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;!-- Project Description --&gt;
      &lt;groupId&gt;org.awax&lt;/groupId&gt;
      &lt;artifactId&gt;toolbox&lt;/artifactId&gt;
      &lt;version&gt;0.1.0&lt;/version&gt;
      &lt;name&gt;ToolBox&lt;/name&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
      &lt;url&gt;http://maven.apache.org&lt;/url&gt;
      &lt;description&gt;Custom library containing useful code&lt;/description&gt;
  
      &lt;!-- Project Properties --&gt;
      &lt;properties&gt;
          &lt;jdk.version&gt;1.7&lt;/jdk.version&gt;
          &lt;!-- Libraries Version --&gt;
          &lt;log4j.version&gt;1.2.17&lt;/log4j.version&gt;
          &lt;jdom.version&gt;2.0.5&lt;/jdom.version&gt;
          &lt;miglayout.version&gt;3.7.4&lt;/miglayout.version&gt;
          &lt;jfreechart.version&gt;1.0.19&lt;/jfreechart.version&gt;
          &lt;bounce.version&gt;0.18&lt;/bounce.version&gt;
          &lt;!-- Maven Plugins Version --&gt;
          &lt;eclipse.version&gt;2.9&lt;/eclipse.version&gt;
          &lt;compiler.version&gt;3.2&lt;/compiler.version&gt;
          &lt;jar.version&gt;2.5&lt;/jar.version&gt;
          &lt;assembly.version&gt;2.4.1&lt;/assembly.version&gt;
          &lt;dependency.version&gt;2.5.1&lt;/dependency.version&gt;
      &lt;/properties&gt;
  
      &lt;!-- Project Libraries --&gt;
      &lt;dependencies&gt;
          &lt;!-- LOG4J --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j&lt;/artifactId&gt;
              &lt;version&gt;${log4j.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- Jdom --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.jdom&lt;/groupId&gt;
              &lt;artifactId&gt;jdom2&lt;/artifactId&gt;
              &lt;version&gt;${jdom.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- MigLayout --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.miglayout&lt;/groupId&gt;
              &lt;artifactId&gt;miglayout&lt;/artifactId&gt;
              &lt;version&gt;${miglayout.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- JFreeChart --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.jfree&lt;/groupId&gt;
              &lt;artifactId&gt;jfreechart&lt;/artifactId&gt;
              &lt;version&gt;${jfreechart.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- Bounce --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.bounce&lt;/groupId&gt;
              &lt;artifactId&gt;bounce&lt;/artifactId&gt;
              &lt;version&gt;${bounce.version}&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;!-- Build Options --&gt;
      &lt;build&gt;
          &lt;pluginManagement&gt;
              &lt;plugins&gt;
                  &lt;!-- Attach source code and Javadoc --&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-eclipse-plugin&lt;/artifactId&gt;
                      &lt;version&gt;${eclipse.version}&lt;/version&gt;
                      &lt;configuration&gt;
                          &lt;downloadSources&gt;true&lt;/downloadSources&gt;
                          &lt;downloadJavadocs&gt;false&lt;/downloadJavadocs&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
                  &lt;!-- Set a JDK compiler level --&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;${compiler.version}&lt;/version&gt;
                      &lt;configuration&gt;
                          &lt;source&gt;${jdk.version}&lt;/source&gt;
                          &lt;target&gt;${jdk.version}&lt;/target&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
                  &lt;!-- Copy project dependencies --&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;${dependency.version}&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;includeScope&gt;provided&lt;/includeScope&gt;
                                  &lt;outputDirectory&gt;${project.build.directory}/dependency&lt;/outputDirectory&gt;
                              &lt;/configuration&gt;
                          &lt;/execution&gt;
                      &lt;/executions&gt;
                  &lt;/plugin&gt;
                  &lt;!-- Create the Jar --&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;${jar.version}&lt;/version&gt;
                      &lt;configuration&gt;
                          &lt;archive&gt;
                              &lt;manifest&gt;
                                  &lt;!-- Jar file entry point --&gt;
                                  &lt;mainClass&gt;${project.groupId}.${project.artifactId}.tools.WaveformGenerator&lt;/mainClass&gt;
                              &lt;/manifest&gt;
                          &lt;/archive&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
                  &lt;!-- Add dependencies to generated Jar --&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;${assembly.version}&lt;/version&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;configuration&gt;
                          &lt;descriptorRefs&gt;
                              &lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt;
                          &lt;/descriptorRefs&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
              &lt;/plugins&gt;
          &lt;/pluginManagement&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>