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"/>
   <tstamp>
     <format property="TODAY" pattern="yyyy-MM-dd HH:mm:ss" />
   </tstamp>

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

  <jar destfile="hello.jar"
       basedir="."
       includes="**/*.class"
       manifest="MANIFEST.MF"
       />
</target>

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=”store.jar.name” value=”MyJarName”/>
       –>
        <property name=“store.jar.name” value=“MarsRoverViewer”/>

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

        <property name=“store.dir” value=“store”/>
        <property name=“store.jar” value=“${store.dir}/${store.jar.name}.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”/>

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

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

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

    </target>

highligted by quickhighlighter

NetBeans – include external libraries

http://www.coderanch.com/t/419419/vc/there-way-netbeans-include-external

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"/>
  </jar>
</target>

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 project.properties file will contain lines like the following for each included library project:

reference.mylib.jar=${project.mylib}/dist/mylib.jar

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.