• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to find unused Jar libs in a huge application?  RSS feed

 
Andi Schmidt
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm a programmer on a huge java web application. I have the problem that i want to upgrade almost all frameworks which are used. And this are a lot of frameworks e.g. Struts, Spring, Hibernate, Axis2, Common Controls and so on. Each of it comes with a lot of Jar-Libs and that's the problem. I'm sure that a lot of these Libs are not used but which? Is there a way to find out which Jars are really used? Which are directly used from my Java Sources i can see really easy but what about Jars which are used from other Jars. I found a Ant-Task named JarJar but this can me only show which jars could be used from other Jars but not if they are really used. Has somebody an idea/tool for this problem?

Greets Andi

PS: I hope everbody can understand my English, i'm not a native speaker
 
Tim Holloway
Bartender
Posts: 18663
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Andi!

This is a question that comes up fairly often, but you won't like the answer. There's no 100% certain way to do this, and the reason is interfaces and reflection. Although the vast majority of Java method calls are done via static linkages, many are not. A method can be called against an interface which is implemented by a dynamically bound object. Or a method name could be synthesized by string-building operations and invoked via the reflection mechanism. Or a class could be completely built up dynamically in binary, but that's an extremely esoteric function that normal apps wouldn't usually do, although some of the more sophisticated libraries might. ORM services are fond of rewriting classes in order to add the functionalities on top of the data model POJOs, for example.

The only real way to find out is to remove the libraries. If the code won't compile, you'll know that there's a direct static link. If it does compile, exercise the code and see if it blows up at runtime due to missing resources. That's hardly definitive, however, since there may be unusual paths that didn't get tested that only occur on alternate Leap Years or something. That particular problem is the main reason I prefer languages with strong compile-time checking (like Java) over "quick" languages like Python. I don't like it when things blow up in a production runtime if there's a way to prevent it.
 
Dawn Charangat
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to check this out: http://classpathhelper.sourceforge.net/

*disclaimer* I haven't used it myself, but read about this in respectable circles
 
Tim Holloway
Bartender
Posts: 18663
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dawn Charangat wrote:You might want to check this out: http://classpathhelper.sourceforge.net/

*disclaimer* I haven't used it myself, but read about this in respectable circles


Ah, another tool to add to my collection!

Unfortunately, there's a paragraph at the bottom titled "Limitations", which basically repeats what I just said. The Class.forName() is a good example, too, since that's commonly used to dynamically load JDBC drivers.

Not to say this is a worthless tool, but its primary intent is to help people resolve problems that resulted in ClassNotFoundExceptions when they darned well know they included the class in their app!
 
Andi Schmidt
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:
This is a question that comes up fairly often ...


Oh, I'm sorry, i tried to find a answere here and with Google, but it seems to me that i have chosen the wrong words for search

Tim Holloway wrote:
...but you won't like the answer.


I was almost sure to hear that. So we have to live with our almost 140 Jars

Thank you
Andi

 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think you need a perfect solution in this case. I would suggest trying a tool such as the one another poster listed and see how far that takes you. If you can remove 10 or 20 files that would even be good especially if the effort is minimal.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!