DEV Community

Claudio Higashi
Claudio Higashi

Posted on

Locating jar files containing a given class in the command line

Have you ever been in a situation where you need to check whether a given Java class is present or not in some jar library in a remote server's filesystem but all you have in your hands is just a *%@!# SSH terminal? You just feel like you have to cross the ocean with a spoon.

In such a case, and if luckily the remote server is running some sort of Linux, then you can use the find command in combination with grep.

The example below will try to locate which jar files contain the class com.ibm.db2.jcc.Db2Driver, starting from the current directory. Notice that we have to replace dots by slashes.

$ find . -name '*.jar' -exec grep -Hs com/ibm/db2/jcc/DB2Driver {} \;
Enter fullscreen mode Exit fullscreen mode

And this is what I got after running the above command:

Binary file ./WEB-INF/lib/db2jcc4-10.5.2.jar matches
Enter fullscreen mode Exit fullscreen mode

I hope this may eventually help you to cross your ocean. But take care. Sometimes there are lots of sharks out there! :-o

Top comments (0)