tags:

views:

227

answers:

2

We have some legacy java applications with many class folders and redundant jars on the classpath. One vendor even ships updates via an "overrides" jar that we must prepend to the classpath. Although clean-up ought to be a medium-term goal, I'm wondering if there are any tools out there that will collapse all these directories/jars into one structure that represents the versions of files that would actually be classloaded in a running system. I guess I could write a script that copies directories on top of each other in the proper order and cracks jars, etc. However, I'm hoping that this has been done already.

OneJar (http://one-jar.sourceforge.net/) can gather up a classpath into an enclosing jar, but it relies on a special classloader implementation to access jars within jars.

The commenter below (who should resubmit this as an answer!) had a good suggestion. I haven't had a chance to test it out yet.

+1  A: 

One part of a solution might be to run a sample session with a code coverage tool. If you ensure that you exercise all functionality of your application, then classes with no coverage are not used and you can filter them out.

In fact it might not be that hard to get a list of classes that are used from the coverage report, then for each class on the list find what JAR/source folder it's defined in and add these to a list (or rather, set). Something I found useful is that the standard Unix grep tool is actually quite usable to see what JAR file a given class is in; though since you can't fully-qualify the name, I expect it will give the occasional false positive and so shouldn't be used in an automated fashion.

Hope this helps you work something out!

Andrzej Doyle
Good idea. This would be an additional benefit. As a first step, I just want to filter out the stuff I know won't be classloaded, like all the Foo classes that are lower in the classpath than the Foo in the Patch1-7-12.jar that's the first classpath item. Yes, it's this bad!
ShabbyDoo
A: 

I usually dont have a problem at all with CLASSPATHS of up to 5000 characters. That being said, I bet I could pass one that is quite a bit longer than that. I did run into an instance a few times where Windows 2000 had a shell limitation and I had to use the XP shell cmd.exe because it held a much longer buffer...

What is the max length of the classpath your trying to pass?

djangofan
My problem is that this classpath contains many "classes" roots and jars, many with classes that override each other based on classpath precedence. I need to drag all this back into my IDE so I can figure out what code is there and what will actually be executed. So, it's not the length itself that is the issue.
ShabbyDoo