首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在webapp中获取当前svn版本

在webapp中获取当前svn版本
EN

Stack Overflow用户
提问于 2008-10-03 10:54:52
回答 5查看 5.7K关注 0票数 9

在java webapp中显示/使用修订号的最佳方式是什么?

我们只使用ant来构建我们的.war存档,没有构建服务器之类的东西。我希望有某种$ref,我可以在资源文件中写入,但这只在有问题的文件提交时才会更新。我需要它在全球范围内。

你有什么推荐的?更新某些文件的提交后触发器?自定义ant脚本?有没有更简单的方法来做这件事?或者最好有我自己的独立于svn的版本号。

编辑:很棒的建议!非常感谢你的回答!

EN

回答 5

Stack Overflow用户

发布于 2008-10-04 21:16:17

我们使用以下ant任务在jar的属性中包含svn版本,以及正在使用的其他包的版本

代码语言:javascript
复制
<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应用中访问它

代码语言:javascript
复制
String version = this.getClass().getPackage().getImplementationVersion();
票数 6
EN

Stack Overflow用户

发布于 2012-07-12 00:34:38

如果您使用的是ant,则可以定义此任务:

代码语言:javascript
复制
 <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>

您可以将修订值放在您想要的位置。

票数 4
EN

Stack Overflow用户

发布于 2008-10-03 10:56:22

参见this thread

在这个线程中,我最喜欢的就是在你想要修改ID的地方转储$Id:$,当你导出的时候,SVN会用真实的数据来填充它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/166322

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档