我正试图在JSF中重写一个遗留应用程序,而其他被重写的应用程序在页脚中发布了maven版本。
我正试图弄清楚他们是如何做到的,到目前为止,我已经弄清楚他们在做什么:
页脚.xhtml
<h:outputText id="fullBuildString" value="#{ApplicationInfo.fullBuildString}" />
ApplicationInfoBacking.java
public class ApplicationInfoBacking {
private String buildTime;
private String iteration;
private String version;
private String inception;
private String fullBuildString;
@PostConstruct
public void init() {
fullBuildString = generateFullBuildString();
}
public String getBuildTime() {
return buildTime;
}
public void setBuildTime(final String buildTime) {
this.buildTime = buildTime;
}
public String getIteration() {
return iteration;
}
public void setIteration(final String iteration) {
this.iteration = iteration;
}
public String getVersion() {
return version;
}
public void setVersion(final String version) {
this.version = version;
}
public String getInception() {
return inception;
}
public void setInception(final String inception) {
this.inception = inception;
}
/**
* @return ApplicationName vVersion (Iteration) BuildTime
*/
public String getFullBuildString() {
return fullBuildString;
}
public String generateFullBuildString() {
if ((version == null) || "".equals(version.trim())) {
version = "Unknown version";
}
if ((iteration == null) || "".equals(iteration.trim())) {
iteration = "Unknown iteration";
}
if ((buildTime == null) || "".equals(buildTime.trim())) {
buildTime = "Unknown build time";
}
final StringBuilder build = new StringBuilder();
build.append("v. ").append(version);
if (!Phase.PRODUCTION.equals(PlatformUtil.getPhase()) && !Phase.BETA.equals(PlatformUtil.getPhase())) {
build.append(" (").append(iteration).append(")");
build.append(" ").append(buildTime);
}
return build.toString();
}
}
faces-config.xml
<managed-bean>
<managed-bean-name>ApplicationInfo</managed-bean-name>
<managed-bean-class>path.to.class.ApplicationInfoBacking</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
<managed-property>
<property-name>buildTime</property-name>
<value>#{initParam.buildTime}</value>
</managed-property>
<managed-property>
<property-name>iteration</property-name>
<value>#{initParam.iteration}</value>
</managed-property>
<managed-property>
<property-name>version</property-name>
<value>#{initParam.version}</value>
</managed-property>
<managed-property>
<property-name>inception</property-name>
<value>#{initParam.inception}</value>
</managed-property>
</managed-bean>
web.xml
<context-param>
<param-name>buildTime</param-name>
<param-value>${buildNumber}</param-value>
</context-param>
<context-param>
<param-name>iteration</param-name>
<param-value>${iteration}</param-value>
</context-param>
<context-param>
<param-name>version</param-name>
<param-value>${pom.version}</param-value>
</context-param>
这是我加载应用程序时实际显示的内容:
v. ${pom.version}
由于某种原因,${pom.version}
没有被解释。
有人知道为什么吗?
看起来他们正在使用buildnumber插件:http://mojo.codehaus.org/buildnumber-maven-plugin/
您需要将其添加到web模块中,然后通过pom.xml中的resources部分启用对web.xml的过滤——我认为不需要更改faces配置。我不知道你可以使用initParam。如果你不能,你仍然可以直接过滤faces配置,以防你的IDE不喜欢过滤web.xml
"pom.version"可能不起作用,因为它已被弃用?尝试使用project.version
拥有来自不同属性文件的maven pom密钥
在应用程序启动时读取属性文件,并将其放入应用程序范围的bean
为了做你想做的事,使用另一个答案中提出的解决方案。。