uber jar using ant

<!-- ant -f uberjar.xml -->
<project name="myproject" default="uber" basedir=".">
  <description>creates uber jar</description>

  <!-- set global properties for this build -->
  <property name="src"   location="src"/>
  <property name="build" location="build"/>
  <property name="dist"  location="."/>
  <property name="main.class"  value="MainClass"/> <!-- you Main-Class name for uber jar -->

  <path id="class.path">
      <pathelement location="c:/lib/one.jar"/>
      <pathelement location="c:/lib/two.jar"/>
      <pathelement location="c:/lib/three.jar"/>
  </path>

  <target name="init">
    <mkdir dir="${build}"/>
  </target>

  <target name="compile" depends="init" description="compile the source " >
    <javac srcdir="${src}" destdir="${build}">
        <classpath refid="class.path"/>
    </javac>
  </target>

  <target name="dist" depends="compile" description="generate the distribution" >
    <jar jarfile="${dist}/${ant.project.name}.jar" basedir="${build}"/>
  </target>

  <target name="uber" depends="compile" description="creating one big fat jar" >
    <jar id="files" jarfile="${dist}/${ant.project.name}.jar" basedir="${build}">
        <manifest>
          <attribute name="Main-Class" value="${main.class}"/>
        </manifest>
        <zipfileset src="c:/lib/one.jar"   includes="**/*.java **/*.class"/>
        <zipfileset src="c:/lib/two.jar"   includes="**/*.java **/*.class"/>
        <zipfileset src="c:/lib/three.jar" includes="**/*.java **/*.class"/>
    </jar>
  </target>

  <target name="clean" description="clean up" >
    <delete dir="${build}"/>
  </target>
</project>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s