0
我想讀取從我的項目的根目錄可訪問的文件夾中的jar的內容,該jar是正確找到,但是,我的代碼只打印名稱在META-INF
文件,這裏是我試過至今:只有meta/inf文件可用於探索jar內容
public static void provideClassList(String jarName) {
List<String> classNames = new ArrayList<String>();
ZipInputStream zip;
try {
zip = new ZipInputStream(new FileInputStream(StaticValues.JARS_PATH.concat(jarName)));
for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) {
System.out.println(entry);//PRINTS META-INF/
if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
String className = entry.getName().replace('/', '.');
classNames.add(className.substring(0, className.length() - ".class".length()));
}
zip.close();
}
// explore content (THIS IS ACTUALLY EMPTY)
for (String className : classNames) {
try {
Class<?> clazz = Class.forName(className);
System.out.println(clazz.getCanonicalName());
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException ex) {
}
}
我看不到任何的權限管理問題,另外,我手動從控制檯打開JAR文件,並且我希望找到的內容都在那裏。 這些都是我從月食看到屬性:
不知道你在做什麼,但如果你只是想列出所有的文件,不需要ZipInputStream(實際上是通過整個文件)。改用'ZipFile'。 –
@CarstenHoffmann我需要實例化包含在我的構建路徑中的jar中的每個類的對象,並調用它的一個方法,將嘗試ZipFile,thx – JBoy
嗨,我是問題的所有者,你可以看問題的解決方案是不是真的與這個問題有關,請你關閉嗎?因爲這可能會誤導其他用戶,並且因爲它沒用,它只會佔用db中的空間。012xthx – JBoy