I want to get the whole file sturcture of a jar file as a tree. I find many solutions. I am deploy it as a zip file. I followed the link How to get names of classes inside a jar file?
Code looks as follow:
public void getClassFromJar(String path) throws IOException {
//ArrayList<String> classNames=new ArrayList<String>();
ZipInputStream zip=new ZipInputStream(new FileInputStream(path));
IntoEntry(zip);
//return classNames;
}
public void IntoEntry(ZipInputStream zip) throws IOException {
for(ZipEntry entry=zip.getNextEntry();entry!=null;entry=zip.getNextEntry()) {
System.out.println("entry: "+entry.getName());
if (entry.getName().endsWith(".jar")) {
// How to do
}
if(entry.getName().endsWith(".class") && !entry.isDirectory()) {
// This ZipEntry represents a class. Now, what class does it represent?
StringBuilder className=new StringBuilder();
for(String part : entry.getName().split("/")) {
if(className.length() != 0) {
className.append(".");
}
className.append(part);
if(part.endsWith(".class")) {
className.setLength(className.length()-".class".length());
}
}
classNames.add(className.toString());
}
}
}
The result from D:\work\workspace\myjar\org.objectweb.asm_2.2.2.jar(It is not in classpath.)
print by System.out.println("entry: "+entry.getName());:
entry: output/
entry: output/dist/
entry: output/dist/lib/
entry: output/dist/lib/asm-2.2.2.jar
entry: output/dist/lib/asm-analysis-2.2.2.jar
entry: output/dist/lib/asm-attrs-2.2.2.jar
entry: output/dist/lib/asm-commons-2.2.2.jar
entry: output/dist/lib/asm-tree-2.2.2.jar
entry: output/dist/lib/asm-util-2.2.2.jar
entry: plugin.xml
How to go into the jar files in this jar file?