Duplicate Package Finder

It’s pretty common to encounter a situation where you want the following question answered.

“Find me the java packages in classpath ‘X’ which are already present in ‘Y’”
where X = Classpath of an application;
and Y = System Classpath or some other classpath

I wrote a small command line utility which answers this question and groks the list of duplicate patterns. For WebLogic Server users, this tool finds the duplicate packages and also emits some xml which can be pasted into ‘META-INF/weblogic-application.xml’ to ensure that the version in the application always wins.

Here’s the usage:

~/code$ java -jar ./utils/dist/dupPkgfinder.jar
Usage: net.nagiworld.utils.DupPackageFinder
      -appclasspath [String] Application Classpath
      -parentclasspath [String] Classpath to compare against
      -advice [flag] Emit Advice for use with WebLogic Server
      -verbose [flag] Show me what's going on

Example: Lets say I have a webapp which uses a specific version of log4j.jar. Since WebLogic already packages a version of log4j.jar in its System Classpath, using a different version requires an explicit descriptor element.

Given that the jar is in WEB-INF/lib, I ask the tool to help me out:

~/code/utils/test$ java -jar ../dist/dupPkgfinder.jar
-parentclasspath $CLASSPATH -appclasspath './WEB-INF/lib/*'
-advice

Duplicate Packages:
org/apache/log4j
org/apache/log4j/chainsaw
org/apache/log4j/config
org/apache/log4j/helpers
org/apache/log4j/jdbc
org/apache/log4j/jmx
org/apache/log4j/lf5
org/apache/log4j/lf5/util
org/apache/log4j/lf5/viewer
org/apache/log4j/lf5/viewer/categoryexplorer
org/apache/log4j/lf5/viewer/configure
org/apache/log4j/net
org/apache/log4j/nt
org/apache/log4j/or
org/apache/log4j/or/jms
org/apache/log4j/or/sax
org/apache/log4j/spi
org/apache/log4j/varia
org/apache/log4j/xml

Recommendation: Add the following snippet to 'META-INF/weblogic-application.xml'.

<prefer-application-packages>
<package-name>org.apache.log4j.*</package-name>
</prefer-application-packages>

If you’re familiar with FilteringClassLoader, then this tool is an excellent aid to creating the filter patterns that should be added to the weblogic-application.xml descriptor. See http://edocs.bea.com/wls/docs92/programming/classloading.html for more details on FilteringClassLoader.

NOTE: Duplicate packages in your application does not necessarily imply that FilteringClassLoader be used. Often times unused jars also end up in WEB-INF/lib

This tool is a thin wrapper our DepHandler from jarjar. In addition to that it also depends on cli-parser which is used for command line parsing. (using cool annotations!). The tool supports wildcards thanks to the jarjarlinks support for wildcards.

You can download the tool here – dupPkgFinder.jar

Enjoy! Please do share your comments and any other cool uses/improvements for the tool :-)

Share
  • del.icio.us
  • Facebook
  • Digg
  • description

Related posts:

  1. AppGen
  2. Code generation using StringTemplate
  3. TML
  4. JavaPolis ’06 Talk online

  • http://www.swingset.com swing sets

    Your duplicate package finder worked wonders for me. I was having troubles sorting and your blog helped me out like anything. I don’t know why there are so few articles about fixing this common problem.

  • http://www.ResumeBuilderPlus.com resume wizard

    this is really cool, I could use this on my documentation.. thanks a lot for sharing this one mate.!

  • http://www.ResumeBuilderPlus.com resume wizard

    this is really cool, I could use this on my documentation.. thanks a lot for sharing this one mate.!

  • Puppies4sale

    Thanks for your valuable tips. This is really an helpful information.

  • johnsame

    I just bookmarked this for my future referance.

    respect
    freanch
    ______________________________________________
    aion kinha | Cheap Aion kinah

  • http://www.bradfordsbakers.com/?target=category&category_id=347 valentines day gifts

    Any addition to improve the tool and likewise make our techie life easier is a welcome.

  • http://www.cherrywoodcomputerdesk.net/ cherry wood computer desk

    Great post, what you said is really helpful to me. I can't agree with you anymore. I have been talking with my friend about, he though it is really interesting as well. Keep up with your good work, I would come back to you.

  • http://www.webaddlink.com/ addlink addurl

    Your website is beautiful and useful. How do I access your site often. Come visit my website at addlink addurl and Linking to websites

  • StefaniB

    Yes, you are right. It is a common situation. We always want this.
    Many thanks for the information. Bets wishes from Stef http://eventsearch.us

  • 276154767

    Aw thank you , you are interesting writ er my friend. That was a great post. I will have to bookmark this site so I can read more later.
    …,

  • http://woodworking-books.org Best Woodworking Plans

    Often times unused jars also end up in WEB-INF/lib

  • http://pulse.yahoo.com/_TZEC6YUQE565ENN7ODAXDMCA7A Rakesh

    HI,
    I have my own transformerFactory, which I added in weblogic-application.xml under ,
    when ever i call generic transformerfactory my transformer-factory given under was getting called,recently in my project they added some tag

    org.apache.*
    com.ctc.wstx.*

    after this my is not getting loaded?what could be the problem,
    I searched in weblogic forums etc..was not able to figure out the problem.
    It will be very helpfull If some one guides me related to this.

blog comments powered by Disqus