我正在尝试在运行时从服务器获取我正在开发的插件的应用程序版本和名称/工件 ID。
我知道我可以使用下面的代码从服务器上生成的 pom.properties 中获取详细信息
java.io.InputStream inputStream = getServletContext().getResourceAsStream("/META-INF/maven/<application-directory-structure>/pom.properties");
Properties mavenProperties= new Properties();
mavenProperties.load(inputStream );
String version = (String) mavenProperties.get("version");
String name = (String) mavenProperties.get("artifactId");
但是我无法访问 pom.properties。
我尝试使用
JarFile.getEntries()
但是因为我无法在运行时获得战争的名称,所以它不起作用。也许此链接可以帮助您:http://technotes.tostaky.biz/2012/08/understanding-absolute-and-relative.html
ps:使用 getResourceAsStream() 了解绝对路径和相对路径
可能有点晚了,但为了记录:我得到了这样的东西来工作:
-不在前导斜杠(“/”)前加上前缀,并且 - 使用 Thread.currentThread().getContextClassLoader().getResourceAsStream(...) 和 - 使用 Maven groupId 和 artifactId
例子
Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/maven/org.apache.logging.log4j/log4j-core/pom.properties");
最佳