Created
April 21, 2012 16:24
-
-
Save ashee/2438147 to your computer and use it in GitHub Desktop.
Ant script that generates jar with properly configured Manifest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8" ?> | |
<project name="mcm2" default="dist" basedir="."> | |
<description> | |
mcm2: hadoop job to compute diagnosis correlation | |
</description> | |
<!-- set global properties for this build --> | |
<property name="src" location="src"/> | |
<property name="build" location="build"/> | |
<property name="dist" location="dist"/> | |
<property name="includeantruntime" value="false" /> | |
<path id="lib.path"> | |
<fileset dir="lib"> | |
<include name="**/*.jar" /> | |
</fileset> | |
</path> | |
<target name="init"> | |
<!-- Create the time stamp --> | |
<tstamp/> | |
<!-- Create the build directory structure used by compile --> | |
<mkdir dir="${build}"/> | |
</target> | |
<target name="compile" depends="init" | |
description="compile the source " > | |
<!-- Compile the java code from ${src} into ${build} --> | |
<javac srcdir="${src}" destdir="${build}" classpathref="lib.path" includeantruntime="false"/> | |
</target> | |
<target name="dist" depends="compile" | |
description="generate the distribution" > | |
<!-- taken from http://martin.ankerl.com/2005/11/30/howto-create-manifestmf-classpath-from-ant/ --> | |
<!-- create a property containing all .jar files, prefix lib/, and seperated with a space --> | |
<pathconvert property="libs.project" pathsep=" "> | |
<mapper> | |
<chainedmapper> | |
<!-- remove absolute path --> | |
<flattenmapper /> | |
<!-- add lib/ prefix --> | |
<globmapper from="*" to="../lib/*" /> | |
</chainedmapper> | |
</mapper> | |
<path> | |
<!-- lib contains all jar files, in several subdirectories --> | |
<fileset dir="lib"> | |
<include name="**/*.jar" /> | |
</fileset> | |
</path> | |
</pathconvert> | |
<jar destfile="${dist}/${ant.project.name}.jar" basedir="${build}"> | |
<manifest> | |
<attribute name="Main-Class" value="org.umich.umms.McmJob"/> | |
<attribute name="Class-Path" value="${libs.project}"/> | |
</manifest> | |
</jar> | |
</target> | |
<target name="clean" | |
description="clean up" > | |
<!-- Delete the ${build} and ${dist} directory trees --> | |
<delete dir="${build}"/> | |
<delete dir="${dist}"/> | |
</target> | |
<target name="run" depends="dist"> | |
<java jar="${dist}/${ant.project.name}.jar" classpathref="lib.path" fork="true"> | |
<arg value="mcm/in" /> | |
<arg value="mcm/out" /> | |
</java> | |
</target> | |
<target name="man" depends="dist"> | |
<manifestclasspath property="mf" jarfile="mcm2.jar"> | |
<classpath refid="lib.path" /> | |
</manifestclasspath> | |
<echo message="${mf}" /> | |
</target> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment