tags:

views:

22

answers:

1

We're using a few libraries that include an xml parser library through maven. We think we've excluded most of those as we are using a newer version.

Is there some sort of JUnit library to check an ear/war for the presence of that jar and fail the test if its there? Or do we just need to write some code to unzip the archive and loop over the directory checking for it?

+1  A: 

Often when this happens, there are classes that appear in both jars, so you can check your classpath looking for duplicates. Given a class, you can see how often it appears on the classpath:

public void testSomeClassInClassPathOnce() {
  String className = SomeClass.class.getName();
  String path = className.replace('.', File.separatorChar) + ".class";
  Enumeration<URL> urls = ClassLoader.getSystemResources(path);
  assertTrue(urls.hasMoreElements());
  urls.nextElement();
  assertFalse(urls.hasMoreElements());
}

If the old jar has a class that isn't in the new one, then you can use ClassLoader.getSystemResource() to see if that class is on your classpath.

Note that you need to make sure your JUnit test has all of the production jars in the classpath.

NamshubWriter