On Java Development

All things related to Java development, from the perspective of a caveman.

Finding the Jar-file Containing a Known Class

without comments

Introduction

This post shows how to locate that jar-file that contains the class you need to import into your project. This is helpful for those times when you’re writing a custom solution using the jar-files from a 3rd party.

The quest is to find the jar-file that contains the class, “XmlHelperUtl“.

In the Java bin directory, there is a utility called “forfiles” that can be used to find it. First, launch a DOS window, then change to the dir containing the slew of jar files to search.

Y:\>cd OIPA\PASJava.war\PASJava.war\WEB-INF\lib

Then execute the “forfiles” command.

Y:\OIPA\PASJava.war\PASJava.war\WEB-INF\lib>forfiles /S /M *.jar /C “cmd /c “C:\PROGRA~1\Java\jdk1.7.0_21\bin\jar” -tvf @file | findstr /C:”XmlHelperUtl” && echo @path”

The answer is printed as:

19611 Thu Jul 17 07:22:38 CDT 2014 com/adminserver/utl/XmlHelperUtl.class
“Y:\OIPA\PASJava.war\PASJava.war\WEB-INF\lib\global.utl-10.0.1.2.jar”

Written by admin

December 10th, 2014 at 11:19 am

Posted in Java Utilities

Leave a Reply

You must be logged in to post a comment.