From: markspace on
Lew wrote:

>
> $ find /cygdrive/c/java/jdk1.6.0_20/ /cygdrive/c/java/glassfish/ -name
> \*.jar \
> | xargs grep ValidatorFactory


Great mind think alike, I suppose. I was having a hard time getting the
class name and the jar name together:

Brenden(a)Homer /cygdrive/c/Program Files/glassfish-v3-b68
$ find . -name "*.jar" -print0 | xargs -0 -I {} jar -tf {} | grep
ValidatorFactory

will find something, but it's not clear where it's finding it.

So a bit of bash shell scripting worked it out.

$ cat findit
#!/bin/bash

jars=`find . -name "*.jar"`

for i in $jars; do
# echo JAR: $i
jar -tf $i | grep ValidatorFactory
if [ $? == 0 ] ; then
echo JAR: $i
fi
done

The output of this script is:

$ ./findit
com/sun/messaging/jmq/jmsclient/validation/ValidatorFactory.class
JAR: ./glassfish/lib/install/applications/jmsra/imqjmsra.jar
javax/validation/ConstraintValidatorFactory.class
javax/validation/ValidatorFactory.class
org/hibernate/validation/engine/ConstraintValidatorFactoryImpl.class
org/hibernate/validation/engine/ValidatorFactoryImpl.class
org/hibernate/validation/util/LazyValidatorFactory.class
JAR: ./glassfish/modules/bean-validator.jar
com/sun/jsftemplating/component/factory/ri/ValidatorFactory.class
JAR: ./glassfish/modules/jsftemplating.jar
org/jboss/webbeans/bean/builtin/DefaultValidatorFactoryBean.class
JAR: ./glassfish/modules/webbeans-osgi-bundle.jar
com/sun/messaging/jmq/jmsclient/validation/ValidatorFactory.class
JAR: ./mq/lib/imq.jar

So yes it's in glassfish/modules/bean-validator.jar for me too.

I think this implies that other containers might use a different .jar
however. JBoss, Weblogic, etc. might supply their own implementation
elsewhere, so the script above might be handy for the OP.
From: Tom Anderson on
On Thu, 22 Apr 2010, markspace wrote:

> Lew wrote:
>
>> $ find /cygdrive/c/java/jdk1.6.0_20/ /cygdrive/c/java/glassfish/ -name
>> \*.jar \
>> | xargs grep ValidatorFactory
>
> Great mind think alike, I suppose. I was having a hard time getting the
> class name and the jar name together:

The handy fact you're missing is that jar files store filenames
uncompressed. You don't need to do jar -tf - you can just grep over the
file. So:

find $SOMEWHERE -name \*.jar -print0 | xargs -0 grep -l ValidatorFactory

Will give you the names of the matching jars. No script needed!

If you wanted jar names and filenames, probably the easiest thing (IMHO)
is a while-read loop:

find $SOMEWHERE -name \*.jar -print0 | xargs -0 grep -l ValidatorFactory | while read jarfile; do echo $jarfile $(jar tf $jarfile | grep ValidatorFactory); done

Saves having to put all the jar names into a variable. But does read each
jar twice.

> So a bit of bash shell scripting worked it out.
>
> $ cat findit
> #!/bin/bash
>
> jars=`find . -name "*.jar"`
>
> for i in $jars; do
> # echo JAR: $i
> jar -tf $i | grep ValidatorFactory
> if [ $? == 0 ] ; then

Kids today! Nobody remembers that the original use of if was directly on
exit statuses:

if jar -tf $i | grep ValidatorFactory
then
whatever
fi

> I think this implies that other containers might use a different .jar
> however. JBoss, Weblogic, etc. might supply their own implementation
> elsewhere

For JBoss 6.0.0.M2, it's $JBOSS_HOME/common/lib/validation-api.jar.

Which is actually exactly what i hypothesised earlier - christ, you know
you've been in the game too long when you can guess the name of the jar
just by looking at the class name.

tom

--
The world belongs to the mathematics and engineering. The world is as
it is. -- Luis Filipe Silva vs Babelfish
From: Tom Anderson on
On Thu, 22 Apr 2010, John B. Matthews wrote:

> In article <alpine.DEB.1.10.1004222312580.7087(a)urchin.earth.li>,
> Tom Anderson <twic(a)urchin.earth.li> wrote:
>
>>> So a bit of bash shell scripting worked it out.
>>>
>>> $ cat findit
>>> #!/bin/bash
>>>
>>> jars=`find . -name "*.jar"`
>>>
>>> for i in $jars; do
>>> # echo JAR: $i
>>> jar -tf $i | grep ValidatorFactory
>>> if [ $? == 0 ] ; then
>>
>> Kids today! Nobody remembers that the original use of if was directly on
>> exit statuses:
>>
>> if jar -tf $i | grep ValidatorFactory
>> then
>> whatever
>> fi
>
> Now, with more parameters!
>
> #!/bin/sh
>
> if [ $# != 2 ]; then
> echo "Usage: `basename $0` path string"
> exit 1
> fi
>
> jars=`find $1 -name \*.jar`
>
> for i in $jars; do
> if jar -tf $i | grep $2; then
> echo JAR: $i
> fi
> done

What i really want is a script which searches the contents of jars. So if
i know i have a resource bundle somewhere in the hojillions of jars which
make up my app that has a key 'crucialMessage', i can find it without
having to know what the file it's in is called.

I think i wrote such a thing as a script at some point; it's not exactly
rocket science. But i don't know where i put it, and i'd like something
that's a bit more efficient than unzipping every jar in turn and then
grepping the results.

tom

--
No man ever steps in the same river twice, for it's not the same river
and he's not the same man. -- Heraclitus
From: Tom Anderson on
On Thu, 22 Apr 2010, markspace wrote:

> Tom Anderson wrote:
>
>> find $SOMEWHERE -name \*.jar -print0 | xargs -0 grep -l
>> ValidatorFactory | while read jarfile; do echo $jarfile $(jar tf
>> $jarfile | grep ValidatorFactory); done
>
> Nice one!
>
>> Kids today! Nobody remembers that the original use of if was directly
>> on exit statuses:
>
> Thanks for pointing that out. I admit I did that script while reading
> the bash scripting How-To. Overall I think it wasn't bad for five
> minutes of study and trial and error. I so seldom write shell scripts,
> nothing sticks in my brain.

Oh, certainly, there was nothing wrong with your script at all, and for
someone who's not in the groove of regular shell scripting to write
something that works at all in five minutes is pretty good!

I only got into read-while loops quite recently myself, so i still like to
pimp them to people who perhaps could benefit from them.

tom

--
No man ever steps in the same river twice, for it's not the same river
and he's not the same man. -- Heraclitus
From: markspace on
Tom Anderson wrote:
>
> What i really want is a script which searches the contents of jars. So
> if i know i have a resource bundle somewhere in the hojillions of jars
> which make up my app that has a key 'crucialMessage', i can find it
> without having to know what the file it's in is called.


I had to use "unzip" to get a pipe for grep, but unzip is available on
Cygwin and is part of the GNU packages, so it should be available to
most folks, so try this, renamed to "jargrep":

$ cat jargrep
#!/bin/bash

if [ $# != 2 ]; then
echo "Usage: `basename $0` path search-string"
exit 1
fi

jars=`find $1 -name \*.jar`

for jar in $jars; do
files=`unzip -Z -1 $jar`
for content in $files; do
if unzip -p $jar $content | grep --binary --label=$jar "$2"; then
echo JAR: $jar RESOURCE: $content
fi
done
done
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: Menu in Swing
Next: [arguably OT] Keyboards