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?

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?
i want to know how a slide will hide
Advertisements
i want to know how a slide will hide
what are the jar files should i add to resolve the Exception(Class org.apache.jsp.index_jsp Not Found) ?
find jar file name from multiple set of jar files
Given a list, identify which are requirements for an EJB-jar file.
How do I decompile Java class files?
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)
I want to know the all possible syntax for EL code to print the first element of an array.
executing a batch file which depends on jar files from a system tray but console should not display.
I want to change my user name on your website ,how can i do this
I want Mini Java Project for Student Admission System. actually i want 2 know how 2 start this...please show me my way.....
Java JAR Files
Need to know struts1 all jar file names
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
class name
i want to copy files from one machine to other using java and the code will be running on third machine
class name
quqtion on jar files
Adding .txt files in a given directory
mahesh want to know java with good understanding
i want to protect mysql database table which user can not view to table and can not copy my table till then us
i want to protect mysql database table which user can not view to table and can not copy my table till then us
Structs jar files
compiling .class files
property hibernate.cache.region.factory_class is not given
autocomplete(): Spring mvc with jquery: I am not getting correct value in the text filed. Please help me
i want to learn Jquery
Get Class Name

Ads