title: How can I test if my jar file has any unresolved dependencies?
body: <p>I'm writing a custom tool to build jar files from our build tree. We like to build "minimal" jar files that contain only the <code>.class</code> files actually referenced from the "root" class (where main() lives) -- and so on, recursively following dependencies.</p>
  
  <p>Historically we have done this by getting <code>javac</code> to follow source dependencies, but that means recompiling common files many many times. (We build 60 or 70 distinct application jars from a single source tree.) I'm writing a new build system that compiles each source file only once, but that means we need to follow dependencies by parsing .class files.</p>
  
  <p>The good news is, I've got working code that does what I want. But I need to be <em>absolutely sure</em> I didn't screw it up, i.e. I want to ensure that I'm building internally consistent jar files, where "consistent" means that all unresolved references can be resolved with one of our known third-party jars.</p>
  
  <p>So ideally I want a MagicTool that I can run like</p>
  
  <pre><code>MagicTool \
    --classpath commons-lang.jar:commons-collections.jar:[...etc...] \
    myapp.jar
  </code></pre>
  
  <p>that will examine every unresolved reference inside <code>myapp.jar</code> and make sure that it can be resolved by one of the third-party jars passed to <code>--classpath</code>. If not, barf.</p>