Finding a JAR that contains a class

L

laredotornado

Hi,

I'm running Java 1.6 on a Tomcat 6.0.26 server. I'm getting a
ClassNotFoundException, comlpaining about
javax.validation.ValidatorFactory. What JAR file is this included in
and is there a generic web site I can visit that will tell me class-
JAR relations and download sites?

Thanks, - Dave
 
M

Mike Schilling

laredotornado said:
Hi,

I'm running Java 1.6 on a Tomcat 6.0.26 server. I'm getting a
ClassNotFoundException, comlpaining about
javax.validation.ValidatorFactory. What JAR file is this included in
and is there a generic web site I can visit that will tell me class-
JAR relations and download sites?

Google :)

This appears to be part of JSR 303, so look for an implementation of that,
 
L

Lew

If it's "javax" then it should be Sun:

Then it has to be Sun. OP: If you see that the package begins with
'java.' or 'javax.', it's part of the Standard API and you should look
in those Javadocs.

Otherwise GIYF.

$ find /cygdrive/c/java/jdk1.6.0_20/ /cygdrive/c/java/glassfish/ -name
\*.jar \
| xargs grep ValidatorFactory
Binary file /cygdrive/c/java/jdk1.6.0_20/jre/lib/rt.jar matches
....
Binary file /cygdrive/c/java/glassfish/glassfish/modules/bean-
validator.jar matches
Binary file /cygdrive/c/java/glassfish/glassfish/modules/container-
common.jar matches
Binary file /cygdrive/c/java/glassfish/glassfish/modules/
jsftemplating.jar matches
....

$ unzip -l /cygdrive/c/java/jdk1.6.0_20/jre/lib/rt.jar
....
(Pattern not found)
....

$ unzip -l /cygdrive/c/java/glassfish/glassfish/modules/bean-
validator.jar
....
291 11-08-2009 20:49 javax/validation/
ValidationProviderResolver.class
1138 11-08-2009 20:49 javax/validation/Validator.class
524 11-08-2009 20:49 javax/validation/ValidatorContext.class
620 11-08-2009 20:49 javax/validation/ValidatorFactory.class
....
 
T

Tom Anderson

I'm running Java 1.6 on a Tomcat 6.0.26 server. I'm getting a
ClassNotFoundException, comlpaining about
javax.validation.ValidatorFactory. What JAR file is this included in
and is there a generic web site I can visit that will tell me class- JAR
relations and download sites?

Funnily enough:

http://findjar.com/

That says:

http://findjar.com/class/javax/validation/ValidatorFactory.html

It's in geronimo-validation_1.0_spec-1.0-CR5.jar:

http://findjar.com/jar/org/apache/g...geronimo-validation_1.0_spec-1.0-CR5.jar.html

Which you can get from:

http://mirrors.ibiblio.org/pub/mirr...-CR5/geronimo-validation_1.0_spec-1.0-CR5.jar

Before you go haring off to download that, i should point out that judging
by the class and jar name, that's part of the new JSR-303 Beans Validation
framework:

http://java.sun.com/javaee/6/docs/tutorial/doc/gircz.html

There may or may not be a vendor-specific version of it you should use in
concert with whatever app server, persistence framework, or whatever
you're using. I would guess it's an API class, though, in which case you
are almost certainly looking for something like validation-api.jar from
Sun, and not whatever that Geronimo thing above is.

tom
 
M

markspace

Lew said:
$ 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@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.
 
T

Tom Anderson

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
 
J

John B. Matthews

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[/QUOTE]

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
 
M

markspace

Tom said:
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.
 
V

vincentdeygas

Hy,

I suggest you this site http://www.jarvana.com/jarvana/

You can use Jarvana site to search for classes and their associated
jar files to resolve NoClassDefFoundError and ClassNotFoundException
issues.
Source code and javadocs can be viewed when available.

Classes, artifacts, and content in the maven central repository are
searchable. You can obtain dependency information for classes and
artifacts, inspect POM files, and inspect plugins.

Vince
 
T

Tom Anderson

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[/QUOTE]

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
 
T

Tom Anderson

Nice one!


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
 
M

markspace

Tom said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top