title: Is it correct or incorrect for a Java JAR to contain its own dependencies?
body: <p>I guess this is a two-part question. I am trying to write my own Ant task (<code>MyFirstTask</code>) that can be used in other project's <code>build.xml</code> buildfiles. To do this, I need to compile and package my Ant task inside its own JAR. Because this Ant task that I have written is fairly complicated, it has about 20 dependencies (other JAR files), such as using XStream for OX-mapping, Guice for DI, etc.</p>
  
  <p>I am currently writing the <code>package</code> task in the <code>build.xml</code> file inside the MyFirstTask project (the buildfile that will package <code>myfirsttask.jar</code>, which is the reusable Ant task).</p>
  
  <p>I am suddenly realizing that I don't fully understand the <em>intention</em> of a Java JAR. Is it that a JAR should <em>not</em> contain dependencies, and leave it to the runtime configuration (the app container, the runtime environment, etc.) to supply it with the dependencies it needs? I would assume if this is the case, an executable JAR is an exception to the rule, yes?</p>
  
  <p>Or, is it <em>the intention</em> for Java JARs to also include their dependencies?</p>
  
  <p>Either way, I don't want to be forcing my users to be copying-n-pasting 25+ JARs into their Ant libs; that's just cruel. I like the way WAR files are set up, where the classpath for dependencies is defined under the <code>classes/</code> directory.</p>
  
  <p>I guess, ultimately, I'd like my JAR structure to look like:</p>
  
  <pre><code>myfirsttask.jar/
      com/  --&gt; the root package of my compiled binaries
      config/  --&gt; config files, XML, XSD, etc.
      classes/  --&gt; all dependencies, guice-3.0.jar, xstream-1.4.3.jar, etc.
      META-INF/
          MANIFEST.MF
  </code></pre>
  
  <p>I <em>assume</em> that in order to accomplish this (and get the runtime classpath to also look into the <code>classes/</code> directory), I'll need to modify the MANIFEST.MF somehow (I know there's a manifest attribute called <code>ClassPath</code>, I believe?). I'm just having a tough time putting everything together, and have a looming/lingering question about the very intent of JARs to begin with.</p>
  
  <p>Can someone please confirm whether Oracle intends for JARs to contain their dependencies or not? And, either way, what I would have to do in the manifest (or anywhere else) to make sure that, at runtime, the classpath can find the dependencies stored under the <code>classes/</code> directory? Thanks in advance!</p>