在java webapp中显示/使用修订号的最佳方式是什么?
我们只使用ant来构建我们的.war存档,没有构建服务器之类的东西。我希望有某种$ref,我可以在资源文件中写入,但这只在有问题的文件提交时才会更新。我需要它在全球范围内。
你有什么推荐的?更新某些文件的提交后触发器?自定义ant脚本?有没有更简单的方法来做这件事?或者最好有我自己的独立于svn的版本号。
编辑:很棒的建议!非常感谢你的回答!
发布于 2008-10-04 21:16:17
我们使用以下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>
然后你可以像这样在你的can应用中访问它
String version = this.getClass().getPackage().getImplementationVersion();
发布于 2012-07-12 00:34:38
如果您使用的是ant,则可以定义此任务:
<target name="version">
<exec executable="svn" output="svninfo.xml" failonerror="true">
<arg line="info --xml" />
</exec>
<xmlproperty file="svninfo.xml" collapseattributes="true" />
<echo message="SVN Revision: ${info.entry.commit.revision}"/>
<property name="revision" value="${info.entry.commit.revision}" />
</target>
您可以将修订值放在您想要的位置。
发布于 2008-10-03 10:56:22
参见this thread。
在这个线程中,我最喜欢的就是在你想要修改ID的地方转储$Id:$
,当你导出的时候,SVN会用真实的数据来填充它。
https://stackoverflow.com/questions/166322
复制相似问题