How to find what jar contains a class?
Hi,
I've often wondered if there's aquickway to find out what jar I need to add to a project, for example when I get a NoClassDefFoundError...
Particularly when deploying projects to app servers, I sometimes get a NoClassDefFoundError and have to look at the package structure of the missing class to try and guess which jar file is required. You can just google for the API docs, but these do not give any indication of known jar files that contain the class...
Thanks in advance
Nick
[527 byte] By [
nick77a] at [2007-10-3 4:18:52]

> I've often wondered if there's a quick way to
> find out what jar I need to add to a project, for
> example when I get a NoClassDefFoundError...
If there is, there wouldn't be such an error. Nobody can tell just given the class name what JAR it belongs to, unless it's a very common library. I doubt anybody would know where com.sprkl.biz.Unseen resides in. You'll have to look into all JARs you have, and that still doesn't cover all the JARs you don't have.
Hint: there's a naming convention for packages. If it's e.g. a org.apache... class, it might be a wise move to look at apache.org for more info. Or reading the documentation of the program you use about the JARs it requires.
> Particularly when deploying projects to app servers,
> I sometimes get a NoClassDefFoundError and have to
> look at the package structure of the missing class to
> try and guess which jar file is required.
You can also look at the EAR manifest, usually. I thought they'd list all libs. At least I always get into trouble if they don't.
> You can
> just google for the API docs, but these do not give
> any indication of known jar files that contain the
> class...
Correct, but the classes usually belong to a certain package that's dovumented to be used in a certain way. One could guess that a MediaCodec class wouldn't necessarily be found in JavaMail.jar.
If you use Eclipse and at least have all the JARs referenced in some build paths, you can hit CTRL-ALT-T (I think - or SHIFT-ALT) to find a certain class, and it'll tell you where it resides. Other IDEs might do that too.