H C   S O F T W A R E   L T D

commanderbond cryptosaurus image jdep spambuddy superstopwatch textscape textscape2 utilities xmogrify xql yago

download (requires java 1.5+), licensed under the GPL license

jdep classpath dependency finder

jdep Finds all the files in a given classpath on which some input classes depend. For example:

$ java -jar jdep.jar --classpath jdep.jar:/tmp/classes uk.co.hcsoftware.jdep.Main

 ns.TaskTimer
 uk.co.hcsoftware.jdep.BadClassFileException
 uk.co.hcsoftware.jdep.ClassFinder
 uk.co.hcsoftware.jdep.ClassFinder$ClassFile
 uk.co.hcsoftware.jdep.ClassFinder$FileClassFile
 uk.co.hcsoftware.jdep.ClassFinder$StreamHandler
 ...
  23 dependencies from inputclasses: [uk.co.hcsoftware.jdep.Main]
  (21 classes in classpath)
 250ms to find dependencies
 266ms in total

Prints all classes on which uk.co.hcsoftware.jdep.Main depends.

Notes

Limitations

Usage

$ java -jar jdep.jar

usage: jdep options inputclass1 [inputclass2.. inputclassn] 
 prints out the fully-qualified names of all the classes referenced by the input class(es)
  -c,--classpath <arg> *  classpath value (same syntax as -cp arg to java ;-de
                           limited)
  -i,--ignore <arg>       ignore any classes whose fully-qualified name starts
                           with one of these values (:-separated list)
  -n,--norecurse          just resolve the input classfile, don't attempt to r
                           esolve the classes it references
  -o,--only <arg>         only include classes whose fully-qualified name star
                           ts with one of these values (:-separated list)
  -q,--quiet              just print out resolved classes (or error message if
                           bad invocation) -no extra info
  -s,--sort               sort output classnames lexically
  -w,--warndynamic        look for invocations of Class.forName(..) and ClassL
                           oader.loadClass(..) and warn about them [nothing is 
                           printed in --quiet mode]
 
 * required options

Usage

Examples

List library dependencies 1:

$ java -jar jdep.jar -s -i java -c cglib-nodep-2.1_3.jar;spin.jar spin.CGLibProxyFactory
Find out what I have to ship from cglib if I use the CGLibProxyFactory with spin (the full cglib-nodep-2.1_3.jar is 324k, whereas the classes I need add up to a mere 196k). Sort the output, and ignore anything in the java package

List library dependencies 2:

$ java -jar jdep.jar -sw -i java:javax:org.w3c -c /tmp/classes:/tmp/jars/jdom.jar:/tmp/jars/swing-layout-1.0.jar uk.co.hcsoftware.commander.Main
Find out what I have to ship from from jdom and swing-layout in order not to get NoClassDefFound errors in CommanderBond (turns out almost everything). Warn about dynamic classloading, and ignore files in the java, javax, org.w3c packages

Auto-generate a ClearCase config.spec:

$ jdep -qs -o uk.co.hcsoftware -c /lib/abc.jar uk.co.hcsoftware.commander.Main | grep -v '\$' | sed -e 's/\./\\/g' -e 's/^/load \\fo_hcs\\java\\src\\/g' -e s/$/.java/g >> config.spec
Write a ClearCase-style list of load rules for all the classes I need to fetch into my source view if I am working on the project the mainclass of which is uk.co.hcsoftware.commander.Main (Excludes inner classes, converts classnames to clearcase paths, prepends the load directive, appends .java

Extract some source files from a library:

$ jdep -c jdnc-0_7-all.jar -s org.jdesktop.swing.JXTable | grep -v \$ | sed -e 's/\./\\/g' -e 's/$/.java/g' > sourcefiles

$ Treecopy /tmp/jdnc/src sourcefiles /tmp/to

First I build a list of all the necessary classes, stripping out inner classes and appending '.java' to the classnames.
Next I use the Treecopy .tscape script to copy the listed files from one directory to another, preserving the tree structure.


ChangeLog

Feb 2006 version 0.1