• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jar file information

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have use of jar file information, like class name and their methods name. I am using following code to list all files contains a particular jar file: -

import java.io.IOException;
import java.util.Enumeration;
import java.util.jar.JarFile;

public class JarFileInfo {

public static void main(String args[]) throws IOException {
JarFile j = new JarFile("jar file path");
Enumeration e = j.entries();

while (e.hasMoreElements()) {
System.out.println(e.nextElement());

}
}
}

Now, How would I get only class names and their respective method names? if I get only class name I can list their methods using following: -
Method[] methods = classnameobj.getDeclaredMethods();
System.out.println("Methods name are as below: -");
int i = 0;
for(Method method : methods) {
System.out.println(method.getName());
methName[i] = method.getName();
i++;

}
so, my problem is only getting all Class names of any particular jar file, any guidance or suggestions plzzzz.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using the JarFile.getInputStream(JarEntry) method you can get at the bytes that make up the class file. Then you can use ClassLoader.defineClass to create a Class object, which you can use to get at the methods.
 
reply
    Bookmark Topic Watch Topic
  • New Topic