title: How to Combine Multiple Jars into One?
body: <p>I've read so many articles/explanations on this and spent too many hours, but everything is either too broad or specific.</p>
  
  <p>This question really only applies to an Applet I've made. It contains one Class, and requires 2 other Jar libraries. I've included these in the projects (multiple projects, because I've tried this in Netbeans and Eclipse...it's easy to recreate a one Class project). The point of all this is that my HTML/web project shouldn't have to deal with more than one Jar or reference them. It's not a complicated applet/project at all either.</p>
  
  <p>Originally, I made it in Netbeans. It has the main package, and after adding the 2 Jars, they are put in a "Libraries" area (the "resources" folder). After building it, Netbeans creates a Jar for my one package/class, and then puts the 2 other libraries in a "lib" directory next to it. I'd like them to be in one, distributable Jar. From the many things I've looked through, I've tried putting the following in build.xml:</p>
  
  <pre><code>&lt;target name="YourBigJar" depends="-post-jar"&gt;
    &lt;jar destfile="dist/BigJar.jar"&gt;
      &lt;zipfileset src="dist/cxapplet.jar"/&gt;
      &lt;zipfileset src="resources/dpotapi.jar"/&gt;
      &lt;zipfileset src="resources/dpotjni.jar"/&gt;
    &lt;/jar&gt;
  &lt;/target&gt;
  </code></pre>
  
  <p>But it produces nothing. I got this from <a href="https://stackoverflow.com/questions/2212913/netbeans-deploying-all-in-one-jar">NetBeans - deploying all in one jar</a> . I don't know/understand how to use build.xml, so I wouldn't be surprised if something's going wrong (obviously), but I get no error/warning messages.</p>
  
  <p>When I made it in Eclipse, it effectively combines them, but when I use the Jar in my actual web project, it says it cannot find the classes from the other 2 Jars. I wouldn't understand how to fix it, but is it a Classpath problem? In Eclipse, I make a new directory called "lib" and put the Jars in it. Then, I right-click the project, go to "Java Build Path", and add the Jars, also checking them under the "Order and Export" tab. From things I've read, I right-click the project, choose "Export", choose "Jar", uncheck the ".classpath" and ".project" files, only check "Export generated class files and resources", and then allow it to generate the manifest file. Like I said, this generates one Jar, but its contents are my package and then a "lib" directory that has the 2 other Jars. The Manifest is there, but it's pretty empty and doesn't reference any files (not sure if that's important). When I put it in my web app, it says the applet can't find the other classes.</p>
  
  <p>It just seems so simple - one package/class, two external Jars...combine into one Jar when built for distribution as an applet. Any ideas?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Since we started using Maven, someone looked into using a Maven plugin. So we ended up creating a new project to house the applet (since it's used across multiple projects), and used this in our <code>pom.xml</code>, in the end:</p>
  
  <pre><code>&lt;build&gt;
    &lt;resources&gt;
      &lt;resource&gt;
        &lt;directory&gt;${basedir}/applet&lt;/directory&gt;
        &lt;excludes&gt;
          &lt;exclude&gt;codesignstore&lt;/exclude&gt;
        &lt;/excludes&gt;
      &lt;/resource&gt;
      &lt;resource&gt;
        &lt;directory&gt;${basedir}/src/main/resources&lt;/directory&gt;
        &lt;filtering&gt;true&lt;/filtering&gt;
      &lt;/resource&gt;
    &lt;/resources&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;artifactId&gt;maven-assembly-plugin&lt;/artifactId&gt;
        &lt;version&gt;2.2-beta-5&lt;/version&gt;
        &lt;configuration&gt;
          &lt;descriptorRefs&gt;
            &lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt;
          &lt;/descriptorRefs&gt;
          &lt;finalName&gt;cxapplet&lt;/finalName&gt;
          &lt;archive&gt;
            &lt;index&gt;true&lt;/index&gt;
            &lt;manifest&gt;
              &lt;addDefaultImplementationEntries&gt;true&lt;/addDefaultImplementationEntries&gt;
            &lt;/manifest&gt;
          &lt;/archive&gt;
          &lt;appendAssemblyId&gt;false&lt;/appendAssemblyId&gt;
        &lt;/configuration&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;id&gt;make-my-applet-jar&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;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-jarsigner-plugin&lt;/artifactId&gt;
        &lt;version&gt;1.2&lt;/version&gt;
        &lt;executions&gt;
          &lt;execution&gt;
            &lt;id&gt;sign&lt;/id&gt;
            &lt;goals&gt;
              &lt;goal&gt;sign&lt;/goal&gt;
            &lt;/goals&gt;
          &lt;/execution&gt;
        &lt;/executions&gt;
        &lt;configuration&gt;
          &lt;keystore&gt;${basedir}/applet/codesignstore&lt;/keystore&gt;
          &lt;alias&gt;codesigncert&lt;/alias&gt;
          &lt;storepass&gt;HIDDEN&lt;/storepass&gt;
          &lt;keypass&gt;HIDDEN&lt;/keypass&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p>And it was nice because it allowed us to use our Code Signing Certificate to automatically sign it too.</p>