Analyzing Dependencies Java

As software developers, we use daily some nice libraries to archive our goals. Of course, the libraries authors also use libraries to get the job done. In practice libraries have a some transitive dependencies. Just take a look a Hibernate, which is brings tons of libraries.



Normally the dependencies are documented somewhere, so that you can include the right one in your project. Also tools like Maven or Ivy help to include the right bits. But what if you have downloaded a project, which brings tons of required and optimal libraries with it and you want to find out the relations-ships?

A small tool called Jar Jar Links can help. Normally this tool is used to merge different jar-files. But it can also scan through jar-files and find out the dependencies.  The command for this is this: java –jar jarjar.jar find jar <list of jars>. For example I analyzed the some parts of Hibernate: java –jar jarjar.jar find jar  hibernate3.jar;./lib/required. The output looks like this:

C:\temp\hibernate\hibernate3.jar -> C:\temp\hibernate\lib\required\slf4j-api-1.5.8.jar
C:\temp\hibernate\hibernate3.jar -> C:\temp\hibernate\lib\required\commons-collections-3.1.jar
C:\temp\hibernate\hibernate3.jar -> C:\temp\hibernate\lib\required\dom4j-1.6.1.jar
C:\temp\hibernate\hibernate3.jar -> C:\temp\hibernate\lib\required\jta-1.1.jar
C:\temp\hibernate\hibernate3.jar -> C:\temp\hibernate\lib\required\javassist-3.9.0.GA.jar
C:\temp\hibernate\hibernate3.jar -> C:\temp\hibernate\lib\required\antlr-2.7.6.jar
C:\temp\hibernate\hibernate3.jar -> C:\temp\hibernate\lib\jpa\hibernate-jpa-2.0-api-1.0.0.Final.jar

You even can list all dependencies of classes to each other, by using: java –jar jarjar.jar find class <list of jars>.

Anyway it’s a small and useful tool. Of course, it only finds dependencies which are compiled into the classes. Stuff which is loaded via reflection cannot be detected.

Tagged on: