Manu Verma

Greenhorn
+ Follow
since Oct 15, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Manu Verma

Sorry, due to some misunderstanding I have posted this topic here, please ignore.
16 years ago
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.
16 years ago
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.
16 years ago
Thanks Brian for concept and explanation, I have used srcpath.replace(File.separatorChar, '.'); and it is working fine.

Thanks to Roseanne Zhang also, you are very true.

I have another problem in same application

I have passed file path(srcpath) in classInfo() method and want to call method listFiles() if given path is a valid folder: -

public static String[] classInfo(String src) {
String[] methName = null;
File file = new File(src);
if (file.isDirectory()) {
listFiles(file);
} else {
array.add(file.getName());
}

But it gives error while creating file Object of File. Any help regarding this? I just want to check whether given path is a folder path or not.
16 years ago
I have use of file path in my application, I have used jFileChooser for getting a folder path, I need folder path not file.
but it is giving path like D:\Eclipse Work\Framework\src, whether "\" is invalid character in Java.
Wndows system use "\\" and Unix uses "/".
I have also used replace('char1', 'char2') method to change the path denotion but it gives error when I use "\".
Please Guide me with suitable solution.

I am using this event code: -

public void OnmouseClickBrowse(java.awt.event.MouseEvent evt) {
String filename = File.separator+"tmp";

JFileChooser fileChooser = new JFileChooser(filename);
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

// Show open dialog; this method does not return until the dialog is closed
fileChooser.showOpenDialog(fileChooser);
File selFile = fileChooser.getSelectedFile();

// Show save dialog; this method does not return until the dialog is closed
fileChooser.showSaveDialog(fileChooser);
selFile = fileChooser.getSelectedFile();
String srcpath = selFile.getPath();
jTextField1.setText(srcpath);

//below line gives error that "\" character in invalid.
//srcpath = srcpath.replace('\','.');
}

Also I want solution to make a UI table/Grid dynamic, means it change the number of rows as per the requirement.
16 years ago
Thanks a ton.
it helped me.
16 years ago
How to check package hierarchy?
Suppose I have to display all classes contains in a Package P1, and P1 contains 2 sub Package P2 and P3. P2 and P3 have also few classes. So how we can check the folder hierarchy?

I have used this -

if (directory.exists())
{
// Get the list of the files contained in the package
String[] files = directory.list();
for (int i = 0; i < files.length; i++)
{
// we are only interested in .class files
if (files[i].endsWith(".class") )
{
// removes the .class extension
classes.add(Class.forName(pckgname + '.' + files[i].substring(0, files[i].length() - 6)));
// checking for SubPackages
}
}
}

But this will display class name of same folder, not checking for subfolder.

So what should I add in above code to check the subfolders and their class files???

Please provide me complete code.
16 years ago
Thanks a ton, I have used this and code is working fine -
public class JarFileInfo {

public static void main(String args[]) throws IOException{
JarFile j = new JarFile("abc.jar");
Enumeration e = j.entries();
while(e.hasMoreElements()){
System.out.println(e.nextElement());
}
}
}
16 years ago
Thanks.
I am working on application which requires the specific, actually I have made this, which displays classes and methods of a particular given method, but it doesn't work for JAR files, and I want to make it for JAR files also.

p


[ UD: Please UseCodeTags ]
[ October 16, 2007: Message edited by: Ulf Dittmer ]
16 years ago
I want make such Java program which can display all classes and their methods & constructors of given Package, also it can read from JAR file.

Means, either I give package path or JAR file path, it should display all contains classes, methods and constructors.
16 years ago