如何自动将编译日期添加到java项目中

时间:2014-12-29 16:33:23

标签: java date compilation

Java中有没有办法让字符串包含程序编译的日期?当我启动我的程序时,我希望它在上次更新时显示,而不必在每次编译之前手动更新它。是否有可能在eclipse中设置我可以用来在每次编译时在代码中插入日期?

public class test {
    public static void main(String[] args) {

        String date = "2014-12-29"; //The string I want to automatically update.

        System.out.println("Last updated: "+date);

    }
}

1 个答案:

答案 0 :(得分:2)

向项目添加包含日期的文件。开始时从文件中读取它。使用Gradle,Maven或Ant等工具构建项目。所有这些都有一种方式来更新带有日期的文件。