在XHTML页面显示构建版本和日期 [英] Displaying version and date of build in the xhtml page

查看:180
本文介绍了在XHTML页面显示构建版本和日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示的内部版本和JSF应用程序的页脚构建日期。该页面是XHTML。我正在寻找的方式来获得的pom.xml或其他文物的信息。

I want to display the build version and build date on the footer of a JSF application. The pages are XHTML. I'm looking for ways to get the information from pom.xml or other artifacts.

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

I found the following that uses maven-replace plugin. http://www.vineetmanohar.com/2010/09/how-to-display-maven-project-version-in-your-webapp/

是否有您使用任何其他技术?

Are there any other techniques you use?

我在寻找这样的事情与JSF - 显示构建日期

I'm looking for something like this with JSF - Displaying the build date

推荐答案

一种方法,将工作:使用Maven过滤把一个文件在你的WAR或包含所需信息的JAR。然后在你的Java Web应用程序,加载该文件的内容作为路径资源的InputStream

One approach that will work: use Maven filtering to put a file in your WAR or JAR containing the required information. Then in your Java webapp, load that file's contents as a ClassPath resource InputStream.

创建一个文件(让我们说buildInfo.properties)在的src / main /资源包含类似:

Create a file (let's say "buildInfo.properties") under src/main/resources containing something like:

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

请注意,由于一个开放的缺陷,你需要定义时间戳属性<性状> 您的POM块:

Note that due to an open defect, you need to define the timestamp property as follows in the <properties> block of your pom:

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

版本&GT; 在你的pom.xml,当您指定

在你的构建,这个文件将与project.version的值(你&LT定义过滤

During your build, this file will be filtered with the value of project.version (which you define with <version> in your pom.xml, when you specify

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

在你的Java code(JSF豆,等等),有code这样的:

In your Java code (JSF bean, whatever), have code like the following:

    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),无需为preceding的Java $ C $加载的属性文件c。

If your framework supports loading properties as "Resource Bundles" from the classpath (i.e. like in Spring), no need for the preceding Java code that loads the properties file.

这篇关于在XHTML页面显示构建版本和日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆