[英]Accessing to pom.xml in jar
public static void main(String[] args) throws IOException {
String filePath = args[0];
JarFile jar = new JarFile(new File(filePath));
Enumeration<JarEntry> zipEntries = jar.entries();
String pomPath = null;
for (JarEntry entry : Collections.list(zipEntries)) {
if (entry.getName().contains("pom.xml")) {
pomPath = entry.getName();
System.out.println(pomPath);
}
}
}
現在它將打印出jar文件中pom.xml所在的位置。 META-INF / maven / ~~~~ / ~~~~ / pom.xml
現在,我想訪問pom.xml文件。 我做了一些研究,我認為我需要使用以下一項
InputStream is = obj.getClass().getClassLoader().getResourceAsStream(pomPath);
調用此方法時,我不知道用於調用obj的內容,因此我只是將null字符串設置為調用對象,並顯示null指針異常。
另外,我看到某個地方需要使用JarInputStream
訪問JarFile
。 但是我不知道使用它。 幫我!
假設您屬於MainClass主類:
MainClass.class.getResourceAsStream("/....");
注意,該路徑必須以斜杠(絕對路徑)開頭,否則它將相對於該類的package目錄。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.