如何到达 pom.properties

问题描述 投票:0回答:2

我正在尝试在运行时从服务器获取我正在开发的插件的应用程序版本和名称/工件 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()
但是因为我无法在运行时获得战争的名称,所以它不起作用。
有什么建议可以让我获得所需的详细信息吗?
我无法修改 Maven 插件来获取工件详细信息。我正在自己制作一个插件,不能为此强制所有应用程序。

java maven pom.xml
2个回答
0
投票

也许此链接可以帮助您:http://technotes.tostaky.biz/2012/08/understanding-absolute-and-relative.html

ps:使用 getResourceAsStream() 了解绝对路径和相对路径


0
投票

可能有点晚了,但为了记录:我得到了这样的东西来工作:

-不在前导斜杠(“/”)前加上前缀,并且 - 使用 Thread.currentThread().getContextClassLoader().getResourceAsStream(...) 和 - 使用 Maven groupId 和 artifactId

例子

Thread.currentThread().getContextClassLoader().getResourceAsStream("META-INF/maven/org.apache.logging.log4j/log4j-core/pom.properties");

最佳

© www.soinside.com 2019 - 2024. All rights reserved.