Is there any way to define a constant value to Java at compile time

后端 未结 7 1019
不知归路
不知归路 2020-12-18 22:59

When I used to write libraries in C/C++ I got into the habit of having a method to return the compile date/time. This was always a compiled into the library so would differe

7条回答
  •  北荒
    北荒 (楼主)
    2020-12-18 23:18

    I remember seeing something similar in an open source project:

    class Version... {
      public static String tstamp() {
        return "@BUILDTIME@";
      }
    }
    

    in a template file. With Ant's filtering copy you can give this macro a value:

    
        
    
    

    use this to create a Version.java source file in your build process, before the compilation step.

提交回复
热议问题