在 java webapp 中显示/使用修订号的最佳方式是什么?
我们只使用 ant 来构建我们的 .war 存档,没有构建服务器等。我希望有某种 if $ref 可以写在资源文件中,但这只会在提交相关文件时更新。我在全局范围内都需要它。
你会推荐什么?更新某些文件的提交后触发器? 自定义 Ant 脚本?有没有更简单的方法来做到这一点? 或者最好有我自己的独立于 svn 的版本号。
编辑:很好的建议!非常感谢您的回答!
最佳答案
我们使用以下 ant 任务在 jar 的属性中包含 svn 版本,以及正在使用的其他包的版本
<target name="package" depends="compile" description="Package up the project as a jar">
<!-- Create the subversion version string -->
<exec executable="svnversion" failifexecutionfails="no" outputproperty="version">
<arg value="."/>
<arg value="-n"/>
</exec>
<!-- Create the time stamp -->
<tstamp>
<format property="timeAndDate" pattern="HH:mm d-MMMM-yyyy"/>
</tstamp>
<jar destfile="simfraserv.jar">
<manifest>
<attribute name="Built-By" value="${user.name} on ${time.date}" />
<attribute name="Implementation-Version" value="${svn.version}" />
<attribute name="Implementation-Java" value="${java.vendor} ${java.version}" />
<attribute name="Implementation-Build-OS" value="${os.name} ${os.arch} ${os.version}" />
<attribute name="JVM-Version" value="${common.sourcelevel}+" />
</manifest>
<fileset dir="bin">
<include name="**/*.class"/>
</fileset>
<fileset dir="src">
<include name="**"/>
</fileset>
</jar>
</target>
然后你可以像这样在你的webapp中访问它
String version = this.getClass().getPackage().getImplementationVersion();
关于java - 在 webapp 中获取当前的 svn 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/166322/