我需要阅读mule项目版本并将其返回给客户端。下面是我的mavenised mule poject的pom.xml文件。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>testproject</artifactId>
<packaging>mule</packaging>
<version>1.0.0-SNAPSHOT</version>
.
.
.
</project>
我想从pom文件中读取上面的版本值(1.0.0-SNAPSHOT)。
有人可以帮忙吗?我怎样才能以推荐的方式获得项目版本。
提前致谢。
答案 0 :(得分:1)
您可以在已过滤的变量中使用$ {pom.version},以便在属性文件中检索它。
想象一个文件src / main / resources / version.properties,其中包含: 版本= $ {pom.version}
然后您可以使用Properties对象:
Properties p = new Properties();
p.load(getClass().getResourceAsStream("/version.properties");
final String version = p.getProperty("version");
答案 1 :(得分:0)
如果您使用的是Maven,我猜游览应用程序将在其名称中包含该版本,例如mule-app-1.0.0-SNAPSHOT。使用Mule表达式语言提取应用程序名称(app.name),如下所述:http://www.mulesoft.org/documentation/display/current/Mule%2BExpression%2BLanguage 然后使用正则表达式从名称中提取版本,并使用http入站端点返回值。
答案 2 :(得分:0)
你有权访问pom文件吗?或来自mule的.zip文件?
如果您有权访问pom.xml文件,则很容易获得该版本。
您需要Unmarshalling功能:
1.-创建一个名为“project”的bean,其中包含groupId,artifactId等以及 version 属性(当然是setter和getter)。
2.-使用unmarshall功能将pom.xml解析为项目bean:
JAXBContext jc = JAXBContext.newInstance(Project.class);
Unmarshaller u = jc.createUnmarshaller();
File f = new File("pom.xml");
Project project = (Project) u.unmarshal(f);
3.-只需获取版本属性:
System.out.println(project.getVersion());
问候。