如這樣一個目錄/Users/xxx/IdeaProjects/abc/web/target/web.jar!/BOOT-INF/lib/rest-0.0.1.jar!/com/tg/tiny/Users/xxx/IdeaProjects/abc/web/target/web.jar這個jar包下的文件目錄可以這樣得到
JarFile localJarFile = new JarFile(new File("/Users/xxx/IdeaProjects/abc/web/target/web.jar"));
Enumeration<JarEntry> entries = localJarFile.entries();
while (entries.hasMoreElements()) {
JarEntry jarEntry = entries.nextElement();
System.out.println(jarEntry.getName());
}
那么這個web.jar里的rest-0.0.1.jar下的文件目錄如何得到?
2 回答

四季花海
TA貢獻1811條經驗 獲得超5個贊
URL url = new URL("jar", null, 0, "file:/Users/xxx/IdeaProjects/web/target/web.jar!/BOOT-INF/lib/rest.jar");
URLConnection con = url.openConnection();
if (con instanceof JarURLConnection) {
JarURLConnection result = (JarURLConnection) con;
JarInputStream jarInputStream = new JarInputStream(result.getInputStream());
JarEntry entry;
while ((entry = jarInputStream.getNextJarEntry()) != null) {
System.out.println(entry.getName());
}
}
添加回答
舉報
0/150
提交
取消