Skip to content

Instantly share code, notes, and snippets.

@vaskoz
Created July 17, 2013 07:40
Show Gist options
  • Save vaskoz/6018520 to your computer and use it in GitHub Desktop.
Save vaskoz/6018520 to your computer and use it in GitHub Desktop.
An example of "jdeps" command line tool in Java 8 with JDeps usage help and 3 different outputs of -v (verbose) -P (profile) and -R (recursive)
import java.util.Set;
import java.util.HashSet;
public class Deps {
public static void main(String[] args) {
System.out.println(Math.random());
Set<String> set = new HashSet<>();
}
}
************** PROFILE ********************
jdeps -P Deps.class
Deps.class -> /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar
<unnamed> (Deps.class)
-> java.io compact1
-> java.lang compact1
-> java.util compact1
************** VERBOSE ********************
jdeps -v Deps.class
Deps.class -> /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar
Deps (Deps.class)
-> java.io.PrintStream
-> java.lang.Math
-> java.lang.Object
-> java.lang.String
-> java.lang.System
-> java.util.HashSet
************** RECURSIVE ********************
jdeps -R Deps.class
Deps.class -> /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar
<unnamed> (Deps.class)
-> java.io
-> java.lang
-> java.util
/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/jce.jar -> /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar
javax.crypto (jce.jar)
-> java.io
-> java.lang
-> java.lang.reflect
-> java.net
-> java.nio
-> java.security
-> java.security.cert
-> java.security.spec
-> java.util
-> java.util.concurrent
-> java.util.jar
-> java.util.regex
-> java.util.zip
-> javax.security.auth
-> sun.security.jca JDK internal API (rt.jar)
-> sun.security.util JDK internal API (rt.jar)
-> sun.security.validator JDK internal API (rt.jar)
javax.crypto.interfaces (jce.jar)
-> java.lang
-> java.math
-> java.security
javax.crypto.spec (jce.jar)
-> java.lang
-> java.math
-> java.security.spec
-> java.util
/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar -> /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/jce.jar
java.security (rt.jar)
-> javax.crypto JDK internal API (jce.jar)
sun.security.util (rt.jar)
-> javax.crypto JDK internal API (jce.jar)
-> javax.crypto.interfaces JDK internal API (jce.jar)
-> javax.crypto.spec JDK internal API (jce.jar)
Usage: jdeps <options> <classes...>
where <classes> can be a pathname to a .class file, a directory, a JAR file,
or a fully-qualified classname or wildcard "*". Possible options include:
-s --summary Print dependency summary only
-v --verbose Print additional information
-V <level> --verbose-level=<level> Print package-level or class-level dependencies
Valid levels are: "package" and "class"
-c <path> --classpath=<path> Specify where to find class files
-p <pkg name> --package=<pkg name> Restrict analysis to classes in this package
(may be given multiple times)
-e <regex> --regex=<regex> Restrict analysis to packages matching pattern
(-p and -e are exclusive)
-P --profile Show profile or the file containing a package
-R --recursive Recursively traverse all dependencies
--version Version information
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment