【发布时间】:2013-10-29 17:34:39
【问题描述】:
我正在使用 JSF、Maven 构建、SVN 在 Java 平台上开发 Web 应用程序。
我已经使用 maven 插件在 jar/war 清单中包含了应用程序版本号、修订版、额外日期。
如何使用页面视图源从浏览器中找到已部署应用程序的版本号(如果我想对最终用户隐藏它)?
stackoverflow.com 在页脚显示版本详细信息,例如2013.10.20.1076 版。
【问题讨论】:
我正在使用 JSF、Maven 构建、SVN 在 Java 平台上开发 Web 应用程序。
我已经使用 maven 插件在 jar/war 清单中包含了应用程序版本号、修订版、额外日期。
如何使用页面视图源从浏览器中找到已部署应用程序的版本号(如果我想对最终用户隐藏它)?
stackoverflow.com 在页脚显示版本详细信息,例如2013.10.20.1076 版。
【问题讨论】:
你可以使用这个maven插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<!-- Impossible de filtrer les ressources web de l'application avec le plugin v2.0.2 Nécessaire pour 'versioner' les .css, .js Maven 2.x WAR Plugin MWAR-134 -->
<version>2.1.1</version>
<configuration>
<!-- Maven 2.x WAR Plugin MWAR-187 regression running war packaging with maven 2.1 Stephane Nicoll added a comment - 07/Jul/09 3:28 AM One way to quickly work around this issue is to deactivate the cache. -->
<useCache>false</useCache>
<webResources>
<resource>
<directory>src/main/webapp</directory>
<!-- Filtering activates replacement of ${pom.version} in *.xhtml... -->
<filtering>true</filtering>
<!-- I've chosen to exlude manually these resources from the filtering -->
<excludes>
<exclude>**/*.xml</exclude>
</excludes>
</resource>
</webResources>
</configuration>
</plugin>
然后,您可以将其插入到您的应用程序的基本 xhtml 模板中(嗯...如果您希望在所有页面上使用它,最终会出现在您的所有页面中):
<span style="display:hidden">${pom.version}"</span>
注意:这将适用于 maven 构建的战争。例如,如果您在使用 Eclipse 测试您的 web 应用程序时不使用 maven,那么您仍然会有 ${pom.version} 未被替换。
【讨论】:
您可以创建一些带有内容的文本静态文件:
version: ${pom.version}
build time: ${build.time}
svn revision: ${svn.revision}
svn path: ${svn.path}
committed date: ${svn.committedDate}
放到src\main\webapp\about\info.txt,使用com.google.code.maven-svn-revision-number-plugin为上述变量提供值:
<build>
<plugins>
.......
<plugin>
<groupId>com.google.code.maven-svn-revision-number-plugin</groupId>
<artifactId>svn-revision-number-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<entries>
<entry>
<prefix>svn</prefix>
</entry>
</entries>
</configuration>
</plugin>
.....
</plugins>
.........
</build>
该文件将在http://your-domain.com/resources/about/info.txt下提供
【讨论】:
另一种可能的选择如下:
使用versions:set -DnewVersion={{YOUR_VERSION_NUMBER}}设置版本。
然后在 maven-war-plugin 中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<archive>
<manifestEntries>
<your-version>${project.version}</your-version>
</manifestEntries>
</archive>
</configuration>
</plugin>
最后可以使用jcabi-manifests做进一步处理。
【讨论】: