how to know what jar file contain my needed class

D

david wolf

When I am using other people's code(say jwsdp tutorial examples) and
try to compile it. sometimes I got compile error. For example, it says
it needs the following package /class:

com.sun.tools.xjc.api

Which jar file contain this package.

Or more generally, when you guys have this kind of problem, how to know
which jar file contain the class I want?

David
 
D

Dave Mandelin

I wrote a program to do this for myself using the JarFile class, but I
doubt it is general or robust enough to be useful to anyone else.
JarBrowser on SourceForge looks like it will do the trick:

http://jarbrowser.sourceforge.net/

There's also a commercial utility (trial version available) that looks
like it will search most kinds of archive files, including jars. (I am
not associated with ZipScan in any way and know nothing about their
product, just found it by googling.)

http://www.zipscan.co.uk/
 
M

Martin Gregorie

david said:
Or more generally, when you guys have this kind of problem, how to know
which jar file contain the class I want?
You didn't say what OS you're using, but I'd use a shell script.
Something like:

for f in *.jar
do
echo "Jar file is $f"
jar t $f | grep classname
done

where 'classname' is the name of the class you're looking for. As a
bonus you'll also be told the package name as well. That works for any
*nix system.

You could do essentially the same in Java by using the JarFile, Manifest
and Pattern classes. Use JarFile to pull the Manifest out of each jar
file and Pattern to search the output stream you can get from the Manifest.
 
L

Lee Peedin

When I am using other people's code(say jwsdp tutorial examples) and
try to compile it. sometimes I got compile error. For example, it says
it needs the following package /class:

com.sun.tools.xjc.api

Which jar file contain this package.

Or more generally, when you guys have this kind of problem, how to know
which jar file contain the class I want?

David

Dang,
I've only been toying with Java for a couple of months and that's one
of the first things I did. And you guys are trying to get him to buy
something. :-(

The "entries" method of "java.util.zip.ZipFile" works on jar files as
well as zip files it will return an enumeration - "size" will tell you
how many files are in the jar.


Lee
 

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
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top