jarファイルのファイル構造全体をツリーとして取得したい。私は多くの解決策を見つけます。zipファイルとして展開しています。リンクをたどった jarファイル内のクラスの名前を取得する方法?
コードは次のようになります。
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());
}
}
}
System.out.println("entry: "+entry.getName());D:\work\workspace\myjar\org.objectweb.asm_2.2.2.jar(It is not in classpath.)
による出力結果 :
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
このjarファイル内のjarファイルに入る方法は?