Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find class name inside a bunch of jars

Tags:

eclipse

I have a whole lot of jar files in my system , related to my Application .

How can i find a particular class in that whole lot of jar files ??

Thank you

like image 991
Pawan Avatar asked Sep 27 '11 10:09

Pawan


2 Answers

If those jar files are in the build path of your Eclipse project:

Ctrl-Shift-T (for "Open Type", "type" as in "class") brings up a search box. You can CamelType (i.e. SB instead of StringBuilder).

like image 193
Thilo Avatar answered Oct 04 '22 00:10

Thilo


You should be able to right-click on the class name in a source file and select one of the sub-items of the Declarations context menu item - i.e., right click on the class name and select Declarations/Project. This will search the project for any declarations of the class and pop up the standard Eclipse search results view. I am assuming that you have the jar as a library in your Eclipse project.

If you want to do this on the file system instead, then use a for loop to iterate over the JAR files and use jar tf FILENAME to get the list of class files and pipe that through grep or findstr (depending on your platform). If you are using bash, something like the following would do the trick:

bash-3.2$ for f in *.jar
do
  result=$(jar tf $f | grep '/DBObject.class$')
  [ -n "$result" ] && echo "$f contains $result"
done
mongodb-api-2.6.3.jar contains com/mongodb/DBObject.class
bash-3.2$ 

You could concoct something similar in Windows using a FOR loop at a command prompt but I don't recall if FINDSTR sets the result ERRORLEVEL correctly. The following should work not completely sure of the syntax:

C:\Directory\Containing\Jars> FOR %I IN (*.jar) DO @(
  FOR /F %J IN ('jar tf %I') DO ECHO "%J: %I"
) | FINDSTR /R /C:"/DBObject.class$"
mongodb-api-2.6.3.jar: com/mongodb/DBObject.class
C:\Directory\Containing\Jars>

If I remember, I'll edit this after I get to a Windows machine.

like image 34
D.Shawley Avatar answered Oct 04 '22 00:10

D.Shawley