I have written a couple of small shell scripts which search Maven for a given class, eg. mvngrep.sh ClassVisitor will find all those jars containing class org.objectweb.asm.ClassVisitor. The next step is to write a java program which searches for an example of the class which contains a particular method signature, and put that jar first in the classpath. Some of our code depends on code that calls the |*visit <http://asm.objectweb.org/current/doc/javadoc/user/org/objectweb/asm/ClassVisitor.html#visit%28int,%20int,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String%5B%5D%29>*(int, int, String <http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true>, String <http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true>, String <http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true>, String <http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true>[])| method of ClassVisitor as opposed to the |*visit <http://asm.objectweb.org/current/doc/javadoc/user/org/objectweb/asm/ClassVisitor.html#visit%28int,%20int,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.lang.String%5B%5D%29>*(int, int, String <http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true>, String <http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true>, String <http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true>[], String <http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true>)| method. But if java or javac finds the old version first, it will try to use it, and won't find the method it needs. The scripts are as follows (if you are using Windows, run them in a CYGWIN shell). The first script calls the second:
--- mvngrep.sh:
#!/bin/sh
if [ "" == "$1" ] ; then
       echo "Usage: $0 class/package: searches Maven's downloaded jars"
       exit 1
fi
mkdir ~/tmp 2>/dev/null
mkdir ~/tmp/allmvnjars/ 2>/dev/null
rm -f ~/tmp/allmvnjars/*jar
find ~/.m2 -name *jar -exec cp -f {} ~/tmp/allmvnjars \;
wargrep.sh ~/tmp/allmvnjars $1
--- wargrep.sh:
#!/bin/sh
if [ "" == "$1" ] || [ "" == "$2" ] ; then
echo "Usage: $0 folder class/package: searches contents of wars and jars"
       exit 1
fi

JARS=`ls $1/*.?ar`
for WAR in $JARS ; do
        RESULT=`jar tvf $WAR | grep $2`
        if [ "" != "$RESULT" ] ; then
               echo "$WAR"
#               echo "$RESULT"
        fi
done





Dan Tran wrote:
the problem is I dont know which jar files has duplicate classes and I have
49 jars in my dep list ;-)

On 3/8/07, Wayne Fay <[EMAIL PROTECTED]> wrote:

> > There are a couple of jars containing the same class in my project.
> >
> > That's bad :)
>
> Yeah, those are my dependency jars :(

Dan, can you not use exclusions etc to get rid of the
artifacts/dependencies which are bringing in these duplicated classes?
I've seen some ugly runtime issues resulting from duplicated classes.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to