gpt4 book ai didi

maven - 在 xhtml 页面中显示版本和构建日期

转载 作者:行者123 更新时间:2023-12-02 03:06:10 25 4
gpt4 key购买 nike

我想在 JSF 应用程序的页脚上显示构建版本和构建日期。这些页面是 XHTML。我正在寻找从 pom.xml 或其他 Artifact 获取信息的方法。

我发现以下使用 maven-replace 插件。 http://www.vineetmanohar.com/2010/09/how-to-display-maven-project-version-in-your-webapp/

您还使用其他技术吗?

我正在寻找与 JSF 类似的东西 - Displaying the build date

最佳答案

一种可行的方法:使用 Maven 过滤将包含所需信息的文件放入 WAR 或 JAR 中。然后在您的 Java Web 应用程序中,将该文件的内容作为 ClassPath 资源加载 InputStream .

src/main/resources 下创建一个文件(假设为“buildInfo.properties”)包含类似的内容:

build.version=${project.version}
build.timestamp=${timestamp}

请注意,由于 an open defect ,您需要定义timestamp属性如下 <properties>你的 pom block :

`<timestamp>${maven.build.timestamp}</timestamp>`

在构建过程中,此文件将使用project.version的值进行过滤(当您指定时,您可以在pom.xml中使用 <version> 进行定义

 <resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>

在您的 Java 代码(JSF bean 等)中,包含如下代码:

    InputStream in = getClass().getClassLoader().getResourceAsStream("buildInfo.properties");
if (in == null)
return;

Properties props = new Properties();
props.load(in);

String version = props.getProperty("build.version");
// etc.

如果您的框架支持从类路径加载属性作为“资源包”(即像在 Spring 中一样),则不需要前面加载属性文件的 Java 代码。

关于maven - 在 xhtml 页面中显示版本和构建日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12426723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com