Use ANT to Build a JAR with version/build number

<target name="jar">
   <delete file="hello.jar"/>
   <property name="version.num" value="1.00"/>
   <buildnumber file="build.num"/>
     <format property="TODAY" pattern="yyyy-MM-dd HH:mm:ss" />

   <manifest file="MANIFEST.MF">
      <attribute name="Built-By" value="${}"/>
      <attribute name="Main-Class" value="howto.Hello"/>
      <attribute name="Implementation-Version" 
      <attribute name="Built-Date" value="${TODAY}"/>                 

  <jar destfile="hello.jar"

Combine JAR Files Into a Single JAR File

    <target name=“package-for-store” depends=“jar”>

        <!– Change the value of this property to be the name of your JAR,
            minus the .jar extension. It should not have spaces.
            <property name=”” value=”MyJarName”/>
        <property name=“” value=“MarsRoverViewer”/>

        <!– don’t edit below this line –>

        <property name=“store.dir” value=“store”/>
        <property name=“store.jar” value=“${store.dir}/${}.jar”/>

        <echo message=“Packaging ${application.title} into a single JAR at ${store.jar}”/>

        <delete dir=“${store.dir}”/>
        <mkdir dir=“${store.dir}”/>

        <jar destfile=“${store.dir}/temp_final.jar” filesetmanifest=“skip”>
            <zipgroupfileset dir=“dist” includes=“*.jar”/>
            <zipgroupfileset dir=“dist/lib” includes=“*.jar”/>

                <attribute name=“Main-Class” value=“${main.class}”/>

        <zip destfile=“${store.jar}”>
            <zipfileset src=“${store.dir}/temp_final.jar”
           excludes=“META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA”/>

        <delete file=“${store.dir}/temp_final.jar”/>


highligted by quickhighlighter

NetBeans – include external libraries

Put something like this at the bottom of build.xml, just before “</project>”:

<target name="-post-jar">
  <jar jarfile="${dist.jar}" update="true">
    <zipfileset src="${dist.jar}" includes="**/*.class" />
    <zipfileset src="${reference.mylib.jar}" includes="**/*.class"/>

You have to change reference.mylib.jar above to match the name of your library. If you have added your libraries to the project with the “Add Project” button in the “Libraries” section of the “Project Properties” dialog, your file will contain lines like the following for each included library project:


The part before “=” is the string you should use in the src attribute of the zipfileset element.

If you have more than one library, add a zipfileset element for each of them.