Skip to content

Instantly share code, notes, and snippets.

@rwoeber
Created March 29, 2011 10:59
Show Gist options
  • Select an option

  • Save rwoeber/892164 to your computer and use it in GitHub Desktop.

Select an option

Save rwoeber/892164 to your computer and use it in GitHub Desktop.
Include svn-revision into ant-build
private static String getApplicationIdentificationString() {
final StringBuilder result = new StringBuilder();
result.append(Application.class.getPackage().getImplementationTitle());
result.append(" ");
result.append(Application.class.getPackage().getImplementationVersion());
return result.toString();
}
<?xml version="1.0" encoding="UTF-8"?>
<project name="fooo" default="build" basedir=".">
<property name="version" value="1.1.6"/>
<property name="mainclass" value="com.example.myapp.Application"/>
<property name="javac_encoding" value="UTF-8"/>
<property name="src.dir" location="src"/>
<property name="classes.dir" location="classes"/>
<property name="lib.dir" location="lib"/>
<property name="config.dir" location="config"/>
<property name="deploy.file" location="${ant.project.name}.jar"/>
<!-- DAD-Framework -->
<fileset id="lib.jars" dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
<path id="all.src.path">
<pathelement location="${src.dir}"/>
</path>
<path id="compile.classpath">
<fileset refid="lib.jars" />
</path>
<!-- Targets -->
<target name="clean" description="Remove build and release directories">
<delete dir="${classes.dir}"/>
<delete file="${deploy.file}"/>
</target>
<target name="build" depends="clean" description="Build jar">
<exec executable="/usr/local/bin/svnversion" failifexecutionfails="no" outputproperty="svn.revision">
<arg value="-n"/>
<arg value="."/>
</exec>
<tstamp>
<format property="timestamp" pattern="yyyy-MM-dd HH:mm"/>
</tstamp>
<mkdir dir="${classes.dir}"/>
<javac destdir="${classes.dir}" debug="false" classpathref="compile.classpath" encoding="${javac_encoding}">
<src refid="all.src.path"/>
</javac>
<jar jarfile="${deploy.file}" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${mainclass}"/>
<attribute name="Built-By" value="${user.name}" />
<attribute name="Built-Date" value="${timestamp}" />
<attribute name="Implementation-Title" value="${ant.project.name}" />
<attribute name="Implementation-Version" value="v${version} r${svn.revision} (${timestamp})" />
<attribute name="Implementation-Java" value="${java.vendor} ${java.version}" />
<attribute name="Implementation-Build-OS" value="${os.name} ${os.arch} ${os.version}" />
</manifest>
<zipgroupfileset refid="lib.jars"/>
<zipfileset file="${config.dir}/db.properties" />
<zipfileset file="${config.dir}/log4j.properties" />
</jar>
</target>
</project>
@vkopichenko
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment