30

I recently have taken the support and programming of a web system written in JSF. The code is kind of messy and redundant, and yes, no documentation exists.

The system has over 40 jar libraries, and most of them are redundant due to old versions and testing. To remove one jar, I must check that it's not imported in the code, so I searched the code for the jar import path (I'm using IntelliJ IDE), made sure that it's not used, and removed it.

However, after compiling the code, a number of run-time errors occurred during testing. I figured out that I removed some jars which are used by other existing jars.

The problem, how do I make sure before removing a jar that it's not used by another jar/java class?

Despite that jars have compiled classes, the compiled classes do have the import path of required libraries. But I can't search them with IntelliJ (does not search inside jars files).

The only way that I'm doing now is to test the system every time I remove a jar and see if I can crash it! This is totally not an easy way due to the huge number of features to be tested.

I wish that there is a tool where I can submit a number of java files/jars, and it displays the dependencies between them.

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
Saleh Al-Zaid
  • 1,299
  • 1
  • 12
  • 12

6 Answers6

22

I know that there was a tool coming out of the JBoss project called JBoss TattleTale, might be worth taking a look:

http://www.jboss.org/tattletale

Uri
  • 88,451
  • 51
  • 221
  • 321
  • 1
    +1 this tool is still very new but gives some good info. It even shows you dependencies between classes in the jar files. Too bad it doesn't work with maven though. – Peter D Apr 24 '09 at 16:59
  • Exactly what I need! I tested it and it provided me with cool reports about the jar dependencies and more. Thanks! – Saleh Al-Zaid Apr 24 '09 at 20:20
  • Glad I could help. I think it uses GraphViz to visualize the graphs, there are ways to tweak it a little to look even better. – Uri Apr 24 '09 at 22:04
7

JDepend will analyze dependencies for you for any number of JARs, class files, etc. Relating the packages it reports to those JARs should be a trivial extra step.

Nick Veys
  • 23,458
  • 4
  • 47
  • 64
  • I tested JDepend too, but it's too far complicated in viewing dependencies than jboss tattletale. But has an advantage, it shows the dependencies between classes too and not just the jars. Thanks – Saleh Al-Zaid Apr 24 '09 at 20:21
2

I also found JarAnalyzer, but it doesn't seem to be maintained anymore.

giraff
  • 4,601
  • 2
  • 23
  • 35
1

Well, it is year 2013 now, so I am not sure whether this tool was great on year 2009. Just used it and found it is useful: Class Dependency Analyzer (CDA) (V1.14) http://www.dependency-analyzer.org/ This tool has a graph UI (Swing?). After add lib jars and Java classes, it will show the dependencies in Class/Package/Container(jar) level. It can also show the dependants as well. So it is easy to find the depend on jars and depended jars.

Anderson Mao
  • 1,101
  • 1
  • 9
  • 7
1

why don't you use Maven for your project? that will help you a lot managing dependencies.

silmx
  • 486
  • 4
  • 12
  • The Maven site plugin will generate reports including dependencies. – Chris Nava Apr 24 '09 at 17:18
  • 1
    The Maven plugin in NetBeans 6.7 includes a graphical dependency viewer for the Jars: http://wiki.netbeans.org/NewAndNoteworthyMilestone3NB67 – mjn Apr 24 '09 at 17:24
-1

There's also ClassDep from the Jini SDK.

http://java.sun.com/products/jini/2.0/doc/api/com/sun/jini/tool/ClassDep.html

JRL
  • 76,767
  • 18
  • 98
  • 146