注入电流的git提交ID为Java web应用 [英] Injecting current git commit id into Java webapp

查看:160
本文介绍了注入电流的git提交ID为Java web应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个包含源代码的几个相关的Java WAR和JAR的一个Git仓库。这将是很好如果Java code能以某种方式:

We have a git repository which contains source for a few related Java WARs and JARs. It would be nice if the Java code could somehow:

System.err.println("I was built from git commit " + commitID);

(显然现实code可能把这个放入HTTP头,记录它在启动时,或什么的,这并不重要,现在)

(Obviously real code might be putting this into an HTTP header, logging it on startup, or whatever, that's not important right now)

我们使用Ant来构建(至少在产品构建,似乎有些程序员在Eclipse我知道更不解的是做好自己的测试)的二进制文件。

We are using Ant to build (at least for production builds, it seems some programmers do their testing from inside Eclipse which I know even less about) binaries.

有没有一个规范的方式来获得当前的git签入我们的Java在构建时提交身份证?如果没有,可以使用Ant来构建人建议,他们会怎么做,我们会看到,如果一个典型的解决方案出现?我敢肯定,我可以创造完全由全棉布自己的东西,但是这似乎是一个可重复使用的构建模块,所以我宁愿不要。

Is there a canonical way to get the commit id for the current git checkout into our Java at build time? If not, can people using Ant to build suggest how they'd do it and we'll see if a canonical solution emerges? I'm sure I can invent something myself entirely from whole cloth, but this seems like a re-usable building block, so I'd rather not.

推荐答案

我不知道是否有用于Git任何Ant任务(我用Google搜索了一下没有成功),反正蚂蚁可以更新的属性与彼得选项文件( git的REV-HEAD解析),然后在运行时使用该属性来获得版本号。这是更清洁和 IDE友好的比有蚂蚁生成一个.java文件。

I don't know if there are any Ant task for git (I googled a bit without success), anyway Ant can update a properties file with Piotr's option (git rev-parse HEAD) and then in runtime use that properties to get the revision number. This is cleaner and IDE friendly than having Ant generating a .java file.

这篇关于注入电流的git提交ID为Java web应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆