Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search Java jar (ear,war,...) files for class / method

I am looking for a tool where I can search several jar, war, ... files for a certain class and method (even better Signature).

So far I have found tools such as JavaClassFinder where I can search for java files and classes. What I would need is to search for methods / signatures as well... I am looking for an existing solution, I do not want to write my own tool.

Example: MyMethod should find all MyMethod methods

Any ideas, suggestions?

---- Edit 2014/March -----

See https://stackoverflow.com/a/23112227/356726

like image 523
Horst Walter Avatar asked Jan 01 '11 13:01

Horst Walter


People also ask

How can I tell what class a JAR is loaded from?

The, the idea is to use find on the root of your classpath to locate all jars, then runs findclass.sh on all found jars to look for a match. It doesn't handle multi-directories, but if you carefully choose the root you can get it to work.

How do you check if a JAR has a class?

You can use Java jar tool. List the content of jar file in a txt file and you can see all the classes in the jar. Also, this won't allow you to inspect annotations, which is likely something you'll want to do if you're scanning classes at runtime.

How do I search for a class file?

Ctrl + H will bring up a Search/Find dialog. One of the tabs is Java which will let you specify what exactly you are looking for e.g. Class/MNethod etc.


2 Answers

I don't know about a standalone tool, but if you create a simple Java project in Eclipse and add the jar, war, etc files to that, you can use the "Java Search" search dialog in Eclipse.

This does exactly what your want and among others has an option to search for methods, and even allows you to filter those on references or declarations.

Alternatively you do have to build something yourself, although you could always use an existing tool as a start, like JavaClassFinder you mentioned or JBoss Tattletale.

like image 113
Arjan Tijms Avatar answered Oct 13 '22 05:10

Arjan Tijms


I just wrote a small (OpenSource) text search utility for JAVA archive files. It can cover your requirement to some extend.

EAR Search can be downloaded from http://sourceforge.net/projects/earsearch

like image 38
guitoo Avatar answered Oct 13 '22 05:10

guitoo