This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes jar file information Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "jar file information" Watch "jar file information" New topic
Author

jar file information

Manu Verma
Greenhorn

Joined: Oct 15, 2007
Posts: 10
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.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41034
    
  43
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.


Ping & DNS - my free Android networking tools app
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: jar file information
 
Similar Threads
Jar File Resources
How to fetch information from a JAR file
WebsphereDeploymentTool for Ant
core java (j2se 5.0) tutorial & package
JarInputStream