java - How can I generate an API version from source? -


i coding api interface in java, , add method client use check if version used server same.

i add thing final string version = "v1.2.3"; want sure version date.

i want prevent fact filed may not updated.

i searching class hash compute @ runtime (or @ compilation time in maven may generated resource file hash).

as using git, maybe git can update special tag in file commit hash , @ runtime return hashcode every source involved api?

how can ?

  1. create class similar this:
package com.company;  import java.io.ioexception; import java.util.properties;  public class versionhelper {     static properties versionprops=new properties();      static     {         try         {             versionprops.load(versionhelper.class.getresourceasstream("/version.properties"));         }         catch (ioexception e)         {             system.err.println("version von "+versionhelper.class.getname()+" kann nicht ermittelt werden");         }     }      public static string getartifactid()     {         return versionprops.getproperty("artifact");     }      public static string getversion()     {         return versionprops.getproperty("version");     }      public static string getbuild()     {         return versionprops.getproperty("build");     }      public static string getbuildtimestamp()     {         return versionprops.getproperty("buildtimestamp");     } } 
  1. create file version.properties in .../src/main/resources. maven default directory resources.

    artifact=${project.artifactid} version=${project.version} buildtimestamp=${build.timestamp} build=${buildnumber} 
  2. add these properties pom.xml

<properties>     <!-- @ http://rterp.wordpress.com/2012/03/16/stamping-version-number-and-build-time-in-properties-file-with-maven/ -->     <build.timestamp>${maven.build.timestamp}</build.timestamp>     <maven.build.timestamp.format>dd.mm.yyyy hh:mm</maven.build.timestamp.format> </properties> 
  1. add <build> section in pom.xml:

    <resources>     <resource>         <directory>src/main/resources</directory>         <filtering>true</filtering>     </resource> </resources> 
  2. then can use methods versionhelper in project


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -