This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes How can you find out what JARs you really use? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How can you find out what JARs you really use?" Watch "How can you find out what JARs you really use?" New topic
Author

How can you find out what JARs you really use?

Andy Poloni
Greenhorn

Joined: Nov 01, 2005
Posts: 2
I'm hoping that this is a problem that others have had to wrestle with ... I've joined a project that includes a ton of JAR files in their WAR, and nobody really knows which ones are actually being used to compile the code (hey, let's just throw them all in the pot). Is there any way using some tool or Eclipse feature to find out which class files from what JARs are really being used for compilation without having to go through all the class files until they all show they're clean?

Many thanks in advance!

Regards,
Andy


Andy<br />SCJP<br />----------- <br />"Silver bullets can kill werewolves AND software development projects."
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I'm not sure this is possible. Thinking about it, class files only contains references to other class files, and not JAR files.

In Eclipse, removing a JAR file from the project should cause a recompilation, and if any dependencies fail, it should report it. Removing JAR files one by one is tedious, but I don't know if there is any other methods.
[ January 10, 2006: Message edited by: Satou kurinosuke ]

[My Blog]
All roads lead to JavaRanch
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

It's not only compile time you have to worry about. If some of those jars are from Apache, for example, then they may be in there because some other Apache project depends on them. This won't show up at compile time, because you already have the compiled version of that some-other-Apache project. But it will show up at run time.

If you really want to do that (you could say it ain't broken so you don't need to fix it), it may come down to good old hard detective work.
Virag Saksena
Ranch Hand

Joined: Nov 27, 2005
Posts: 71
Interesting problem, and it is solvable, I am sure if you search around you might find some tools which does it too...
Here is what you might have to do ..
#1. Find all the bytecodes in your application cause a class to be loaded
#2. Find the class being loaded
#3. Find the jar file the class was loaded from
#4. Print a dependency statement for the class loading and the class being loaded

Good luck


<a href="http://www.auptyma.com" target="_blank" rel="nofollow">The Peak of Performance</a>
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

#5 Have a few coffee breaks and don't forget to bring your pillow too
Andy Poloni
Greenhorn

Joined: Nov 01, 2005
Posts: 2
I'm not sure this is possible. Thinking about it, class files only contains references to other class files, and not JAR files.


That's true in the compilation/execution sense, but your IDE controls what class files are visible to your project. I was hoping that somewhere there might be some feature of Eclipse (or perhaps a plug-in) that built a list of the class files (and where they originate from, i.e. what file system location) that are currently visible to your project (but which aren't actually IN your project). Whenever you add/delete/reorder the build path this list would get updated. Any Eclipse/MyEclipse developers listening out there???

In Eclipse, removing a JAR file from the project should cause a recompilation, and if any dependencies fail, it should report it. Removing JAR files one by one is tedious, but I don't know if there is any other methods.


The emphasis there is on the word tedious.

It's not only compile time you have to worry about. If some of those jars are from Apache, for example, then they may be in there because some other Apache project depends on them. This won't show up at compile time, because you already have the compiled version of that some-other-Apache project. But it will show up at run time.


This is true, but I'd like to sort out the compilation mess first and then deal with the runtime issues after we get that far.

Good luck


Was that said with the same tone of voice as "trust me"???

Thanks for the input!
 
Don't get me started about those stupid light bulbs.
 
subject: How can you find out what JARs you really use?
 
Similar Threads
How to find unused Jar libs in a huge application?
Loading of jar files for a Application
Running Applet from DLL
Finding Classes in Jars
ClassNotFound Exception..