Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / January 2007

Tip: Looking for answers? Try searching our database.

searching jars for a class..

Thread view: 
maya - 12 Jan 2007 15:09 GMT
hi,

if you have a bunch of jars in a directory, is it possible to search for
a class?  I mean if you don't know in what jar the class is..

thank you..
Andrew Thompson - 12 Jan 2007 15:22 GMT
...
> if you have a bunch of jars in a directory, is it possible to search for
> a class? ..

Sure, but it will almost certainly not sort 'the problem'.

>... I mean if you don't know in what jar the class is..

Why not?  Were these Jar's supplied without
documentation?  Did you make them?

Andrew T.
maya - 12 Jan 2007 15:29 GMT
> ...
>> if you have a bunch of jars in a directory, is it possible to search for
[quoted text clipped - 8 lines]
>
> Andrew T.

this is at work, trying to implement search functionality for a website
I'm building, and getting error that am missing a certain bean..  wanted
to search for it (no, documentation is not very good..)  I need to talk
to the back-end guys, but first wanted to search for bean myself..  (and
there are SO MANY jars with "search" name in them..)

thank you..
Lew - 13 Jan 2007 16:58 GMT
>> ...
>>> if you have a bunch of jars in a directory, is it possible to search for
>>> a class? ..
>>> ... I mean if you don't know in what jar the class is..

Andrew Thompson wrote:
>> Why not?  Were these Jar's supplied without
>> documentation?  Did you make them?

On a UNIX shell, or Windows/cygwin, you can use

find $dir -name \*.jar -exec grep -e $ClassName '{}' \;

from the shell prompt, where $dir is a directory (or a set of directories)
somewhere above the JARs and $ClassName is the name of the class of interest.

- Lew
Daniel Dyer - 12 Jan 2007 16:56 GMT
> hi,
>
> if you have a bunch of jars in a directory, is it possible to search for  
> a class?  I mean if you don't know in what jar the class is..
>
> thank you..

This is what I use (you'll need an appropriate shell - i.e. not the  
Windows default shell):

  find . -name *.jar -exec sh -c 'jar -tf {}|grep -H --label {} <pattern>'  
\;

This searches recursively in the current directory.  <pattern> is  
classname, partial classname or regular expression.  For convenience, this  
can be turned into a shell script that takes the pattern as a parameter.

Dan.

Signature

Daniel Dyer
http://www.uncommons.org

Tom Hawtin - 12 Jan 2007 19:20 GMT
>   find . -name *.jar -exec sh -c 'jar -tf {}|grep -H --label {}
> <pattern>' \;

With more than one jar, you will need to double quote the name:

find . -name "*.jar" -exec ...

Tom Hawtin
Daniel Dyer - 12 Jan 2007 19:50 GMT
>>    find . -name *.jar -exec sh -c 'jar -tf {}|grep -H --label {}  
>> <pattern>' \;
>
> With more than one jar, you will need to double quote the name:
>
> find . -name "*.jar" -exec ...

I use bash and it's not a problem.  I just tried some of the other shells  
on my machine - sh and ksh didn't need the quotes, only csh did.

Dan.

Signature

Daniel Dyer
https://watchmaker.dev.java.net - Evolutionary Algorithm Framework for Java

Tom Hawtin - 12 Jan 2007 20:08 GMT
>> With more than one jar, you will need to double quote the name:
>>
>> find . -name "*.jar" -exec ...
>
> I use bash and it's not a problem.  I just tried some of the other
> shells on my machine - sh and ksh didn't need the quotes, only csh did.

I use bash also. All of them should expand filename globs. Presumably
you have a version of find which unusually accepts multiple arguments to
-name.

Tom Hawtin
Lew - 13 Jan 2007 17:05 GMT
>>> With more than one jar, you will need to double quote the name:
>>>
>>> find . -name "*.jar" -exec ...

Daniel Dyer wrote:
>> I use bash and it's not a problem.  I just tried some of the other
>> shells on my machine - sh and ksh didn't need the quotes, only csh did.

> I use bash also. All of them should expand filename globs. Presumably
> you have a version of find which unusually accepts multiple arguments to
> -name.

More likely, Daniel invoked the command from a cwd without any JAR files in
it. Absent any valid expansion of the wildcard, bash leaves it intact.

- Lew
Daniel Dyer - 16 Jan 2007 20:32 GMT
>> I use bash also. All of them should expand filename globs. Presumably  
>> you have a version of find which unusually accepts multiple arguments  
[quoted text clipped - 4 lines]
>
> - Lew

Yes, that's exactly what I did.  Thanks for clearing up the discrepancy.

Dan.

Signature

Daniel Dyer
https://watchmaker.dev.java.net - Evolutionary Algorithm Framework for Java

Lew - 13 Jan 2007 17:02 GMT
Daniel Dyer wrote:
>> find . -name *.jar -exec sh -c 'jar -tf {}|grep -H --label {} <pattern>' \;

This is superior to the "find" that I posted. Mine depended on the fact that
the file name is searchable in the binary JAR file, this one actually searches
the table of contents.

> With more than one jar, you will need to double quote the name:
>
> find . -name "*.jar" -exec ...

or single-quote the filename pattern.

-Lew "picky, picky, picky"


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.