How to list dependencies of a JAR

There is a new tool since JDK 8: jdeps

https://wiki.openjdk.java.net/display/JDK8/Java+Dependency+Analysis+Tool

jdeps is a new command-line tool added since JDK 8 for developers to use to understand the static dependencies of their applications and libraries. jdeps is a static analysis tool on the given class files


JarAnalyzer:

a dependency management utility for jar files. It's primary purpose is to traverse through a directory, parse each of the jar files in that directory, and identify the dependencies between the jar files. The output is an xml file representing the PhysicalDependencies between the jar files.

For more information on PhysicalDependencies, including a variety of design patterns, check out Extensible Java...


You can do the following (if its a maven project):

mvn dependency:tree

It shows transitive dependencies as well, making it very useful to debug dependency conflicts.


If you use maven (as I understood), you can simply use Maven Dependency plugin.

First you need to write a basic pom.xml with all your jars, you can copy this example (i use hibernate as example), and substitute your jars :

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
       <modelVersion>4.0.0</modelVersion>
       <groupId>com.mycompany.app</groupId>
       <artifactId>my-app</artifactId>
       <version>1.0-SNAPSHOT</version>
       <packaging>jar</packaging>
       <name>Maven Quick Start Archetype</name>
       <url>http://maven.apache.org</url>
       <dependencies>
          <dependency>
             <groupId>org.hibernate</groupId>
             <artifactId>hibernate-core</artifactId>
             <version>3.5.0-Final</version>
          </dependency>
<!-- add here other dependencies -->
       </dependencies>
    </project>

then open terminal, go into the containing folder of the pom.xml above and run this command :

mvn dependency:tree

this will print a list of dependencies...

or if you want download and copy in a folder all dependencies run the following command :

mvn dependency:copy-dependencies

you'll find all your dependencies in folder ./target/dependencies


Tattleltale is a tool from JBoss which does this

tattletale.jboss.org/