title: Define constants before init in ant/netbeans
body: <p>I have a webapp to be ran on Tomcat6/JbossAS 5 and, for versioning purposes, I have several AND targets that will perform a set of operations to define a constant with version number and build datetime.</p>
  
  <p>The targets perform the following:</p>
  
  <ol>
  <li>Delete the Release.java</li>
  <li>Copy the Release.template to Release.java with the versioning info properly set as a constant (public static final String)</li>
  </ol>
  
  <p>The thing is that, the constant references are replaced on the code before compilation. For instance, where I have</p>
  
  <pre><code>log.debug("Release: " + Release.info);
  </code></pre>
  
  <p>I can see, using java decompiler, the following (let's assume that "TO_BE_DEFINED" is the initial value for Relase.info):</p>
  
  <pre><code>log.debug("Release: TO_BE_DEFINED");
  </code></pre>
  
  <p>The targets are the following:</p>
  
  <pre><code>&lt;target name="build-config" &gt;
      &lt;!-- config --&gt;
      &lt;property name="project.name" value="MY PROJECT" /&gt;
      &lt;property name="release.prefix" value="MPROJECT" /&gt;
      &lt;property name="release.num" value="1.0" /&gt;
      &lt;property name="release.info.file.path" value="org/my/project/Release" /&gt;
      &lt;tstamp&gt;
          &lt;format property="release.date" pattern="yyyy-MM-dd HH:mm:ss z" /&gt;
      &lt;/tstamp&gt;
      &lt;!-- end config --&gt;
      &lt;property name="release.version" value="${release.prefix}-${release.num}" /&gt;
      &lt;property name="release.info" value="${release.version} ${release.date}" /&gt;
  &lt;/target&gt;
  &lt;target name="build-replace"&gt;
      &lt;filter token="release.info" value="${release.version} ${release.date}" /&gt;
      &lt;delete file="${src.dir}/${release.info.file.path}.java" /&gt;
      &lt;copy file="${src.dir}/${release.info.file.path}.template" tofile="${src.dir}/${release.info.file.path}.java" filtering="true" /&gt;
  &lt;/target&gt;
  
  &lt;target name="build-myproj-1.0.jar" depends="init,buil-config,build-replace,compile"&gt;
      &lt;mkdir dir="${dist.dir}"/&gt;
      &lt;jar compress="true" jarfile="${dist.dir}/MPROJECT-1.0.jar"&gt;
          &lt;fileset dir="${build.classes.dir}"
                 excludes="META-INF/*.*, WEB-INF/classes/*.xml"
                 includes="**/*.class"
          /&gt;
          &lt;manifest&gt;
              &lt;section name="${project.name}"&gt;
                  &lt;attribute name="Release-Version" value="${release.version}" /&gt;
                  &lt;attribute name="Release-Date" value="${release.date}" /&gt;
              &lt;/section&gt;
          &lt;/manifest&gt;
      &lt;/jar&gt;
  &lt;/target&gt;
  </code></pre>
  
  <p>and my class is defined as</p>
  
  <pre><code>public abstract class Release {
  
  /** Release info */
  public static final String INFO = "TO_BE_DEFINED";
  }
  </code></pre>
  
  <p>I understand that this may be a little bit confusing and if I'm missing some information please feel free to ask</p>