Skip to content

Instantly share code, notes, and snippets.

@aembleton
Created August 21, 2012 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aembleton/3416674 to your computer and use it in GitHub Desktop.
Save aembleton/3416674 to your computer and use it in GitHub Desktop.
Ant script that packages up all of the jars into a single executable jar
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project basedir="." default="jar" name="jar">
<property environment="env"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>
<path id="DataPersist.classpath">
<pathelement location="bin"/>
<pathelement location="lib/commons-cli-1.1.jar"/>
<pathelement location="lib/commons-io-1.2.jar"/>
<pathelement location="lib/rabbitmq-client.jar"/>
<pathelement location="lib/slf4j-log4j12-1.6.6.jar"/>
<pathelement location="lib/slf4j-api-1.6.6.jar"/>
<pathelement location="lib/asm-4.0.jar"/>
<pathelement location="lib/kryo-debug-2.19.jar"/>
<pathelement location="lib/minlog-1.2.jar"/>
<pathelement location="lib/objenesis-1.2.jar"/>
<pathelement location="lib/reflectasm-1.07.jar"/>
<pathelement location="lib/log4j-1.2.17.jar"/>
<pathelement location="lib/mysql-connector-java-5.1.21-bin.jar"/>
<pathelement location="lib/blerg-models.jar"/>
</path>
<target name="init" depends="clean">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="DataPersist.classpath"/>
</javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target name="Run">
<java classname="net.blerg.dataPersist.Run" failonerror="true" fork="yes">
<classpath refid="DataPersist.classpath"/>
</java>
</target>
<target name="copyLibs" depends="build-project">
<unzip dest="bin">
<fileset dir=".">
<include name="**/*.jar"/>
</fileset>
</unzip>
</target>
<!-- The copyLibs target copies all of the jars into the root of the jar so this needs to be cleaned up-->
<target name="removeJars" depends="copyLibs">
<delete>
<fileset dir="bin" includes="*.jar" />
</delete>
</target>
<target name="buildJar" depends="build,copyLibs,removeJars">
<jar destfile="blerg-dataPersist.jar" basedir="bin" includes="**/*.class **/*.properties **/*.jar" manifest="MANIFEST.MF" />
</target>
<target name="jar" depends="buildJar" >
<!-- jar has been built, now just remove the bin directory so that it doesn't polute the dev environment -->
<delete dir="bin"/>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment