public void readJarFile() throws IOException {
String jarFilePath = getJarFilePath();
JarFile jarFile = new JarFile(new File(jarFilePath));
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry jarEntry = entries.nextElement();
String innerPath = jarEntry.getName();
if (innerPath.endsWith("MANIFEST.MF")) {
InputStream inputStream = jarFile.getInputStream(jarEntry);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
String line = null;
while (null != (line = bufferedReader.readLine())) {
//这里处理mf文件,读取项目名称和版本
}
bufferedReader.close();
}
}
jarFile.close();
}
public String getJarFilePath() throws FileNotFoundException {
ApplicationHome h = new ApplicationHome(getClass());
File jarFile = h.getSource();
return jarFile.getAbsolutePath();
}
SpringBoot获取项目名称
最新推荐文章于 2024-06-23 22:36:43 发布