/ blog / java / depfind.html

Root Beer Logo Root Beer

Chris Nokleberg's Fizzy Weblog

December 2004
Su M Tu W Th F Sa
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 30 31
Previous  |  Next  |  More...
#  Finding dependencies with JarJar

A while ago Hani (yes that Hani) asked for a simple tool to find dependencies between two codebases. Implementing this as part of JarJar was pretty straightforward, but I didn't have time to clean it up and document it until now.

Here is an example which will find all dependencies between hibernate3.jar and jaas.jar:

  $ java -jar jarjar.jar --find hibernate3.jar jaas.jar
  org/hibernate/jca/ManagedConnectionFactoryImpl -> javax/security/auth/Subject
  org/hibernate/jca/ManagedConnectionImpl -> javax/security/auth/Subject

You can also specify multiple jar files for each classpath, and omitting the second classpath will cause the first classpath to be searched against itself. There is also a "--level=jar" switch which will only print jar->jar dependencies, instead of every class dependency. Using all these tricks together it becomes easy to list all dependencies between a set of jar files:

  $ java -jar jarjar.jar --find --level=jar j1.jar:j2.jar:j3.jar:j4.jar

Run against all the jakarta commons libraries (with the exception of logging), this produces something like:

  commons-beanutils-1.6.1.jar -> commons-collections-3.1.jar
  commons-betwixt-0.5.jar -> commons-digester-1.5.jar
  commons-betwixt-0.5.jar -> commons-beanutils-1.6.1.jar
  commons-betwixt-0.5.jar -> commons-collections-3.1.jar
  commons-cli-1.0.jar -> commons-lang-2.0.jar
  commons-codec-1.2.jar -> commons-codec-1.3.jar
  commons-dbcp-1.2.1.jar -> commons-pool-1.2.jar
  commons-dbcp-1.2.1.jar -> commons-collections-3.1.jar
  commons-digester-1.5.jar -> commons-collections-3.1.jar
  commons-digester-1.5.jar -> commons-beanutils-1.6.1.jar
  commons-jxpath-1.2.jar -> commons-beanutils-1.6.1.jar
  commons-pool-1.2.jar -> commons-collections-3.1.jar
  commons-validator-1.1.3.jar -> commons-collections-3.1.jar
  commons-validator-1.1.3.jar -> commons-beanutils-1.6.1.jar
  commons-validator-1.1.3.jar -> commons-digester-1.5.jar

Currently this simple text output is the only available format, but there is already plumbing to support different output styles, so hopefully I can add direct graphviz or svg output soon. However, even now it is not hard to massage this data into a nice picture (I used Dot, Sodipodi, and Batik, FWIW):

[Dependency Graph]

The core JarJar repackaging functionality is also coming along. You can now transform a jar file via an API, an Ant task, or a command-line utility, something I wish more projects would take the time to allow. JDK 1.5 support is also almost complete--annotations should now be transformed properly, but generics support is still needed. After that, the biggest missing piece for a 1.0 release will be merging of Jar manifests.

[Powered By FreeMarker]  [Valid Atom 1.0]  [Weblog Commenting by]