I want to know the given class name exists in which jar file?

Ads
 

I want to know the given class name exists in which jar file?

I want to know the given class name exists in which jar file? C:\Program Files\IBM\IBMIMShared\plugins in this path around 600 jar files are there. i want to know the name of the jar file where 'com.rational.ft.util.debug' class exists.

View Answers

February 17, 2011 at 5:57 PM

Java find the jar of the given class

import java.io.*;
import java.util.*;
import java.util.jar.*;

class OnlyExt implements FilenameFilter{
  String ext;
  public OnlyExt(String ext){
  this.ext="." + ext;
  }
  public boolean accept(File dir,String name){
  return name.endsWith(ext);
  }
}
public class FindJar{

 private static boolean debug = true;

 public static void getClasseNamesInPackage(String packageName){
   ArrayList classes = new ArrayList();

   packageName = packageName.replaceAll("\\." , "/");
   if (debug) 
   try{
       FilenameFilter ff = new OnlyExt("jar");
        File folder = new File("C:/Program Files/Java/jdk1.6.0_20/lib/");
        File[] files = folder.listFiles(ff);
        for(int i=0;i<files.length;i++){
     JarInputStream jarFile = new JarInputStream(new FileInputStream (files[i].getPath()));
     JarEntry jarEntry;

     while(true) {
       jarEntry=jarFile.getNextJarEntry ();
       if(jarEntry == null){
         break;
       }
       if((jarEntry.getName ().startsWith (packageName)) &&
            (jarEntry.getName ().endsWith (".class")) ) {
         if (debug) System.out.println  ("Found " + jarEntry.getName().replaceAll("/", "\\.")+" in "+files[i].getName());
         classes.add (jarEntry.getName().replaceAll("/", "\\."));
       }
     }
        }
   }
   catch( Exception e){
     e.printStackTrace ();
   }
}
  public static void main (String[] args){
   FindJar.getClasseNamesInPackage("org.jfree.chart.ChartFactory");
   }
}

Ads









Related Tutorials/Questions & Answers:
I want to know the given class name exists in which jar file?
find jar file name from multiple set of jar files
Advertisements
what are the jar files should i add to resolve the Exception(Class org.apache.jsp.index_jsp Not Found) ?
i want to know how a slide will hide
i want to know how a slide will hide
Given a list, identify which are requirements for an EJB-jar file.
Java JAR Files
How do I decompile Java class files?
Need to know struts1 all jar file names
executing a batch file which depends on jar files from a system tray but console should not display.
i want to save image on server folder. and i want to save URL of this folder and name of image in database
I want to know how can I create sessionfactory in hibernate 4 (latest version)
How to use JAR file in Java
I want to know the all possible syntax for EL code to print the first element of an array.
I want to change my user name on your website ,how can i do this
quqtion on jar files
I want Mini Java Project for Student Admission System. actually i want 2 know how 2 start this...please show me my way.....
Structs jar files
i want to copy files from one machine to other using java and the code will be running on third machine
class name
could you suggest me that in which area i have to do a project?i want a complete guidence to complete my project.
i want to create an application with only a button which on click displays table from database using struts2 and hibernate on eclipse
Adding .txt files in a given directory
How to run java swing application from jar files .
compiling .class files
cannot open .jar files by double click
class name
autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me
mahesh want to know java with good understanding
Get Class Name
How to convert many class files into one exe file?

Ads