Skip to main content

Posts

Showing posts with the label Ant

Ant Script to make Executable JAR

Recently I observed search patterns about Ant script to make executable JAR files, many end up on wrong pages of my blog. This blog post is for those who are searching for it. Its fairly easy and simple to use Ant Script, to make an executable JAR file, see the script below. <jar destfile="_dist/my-executable-jar.jar">     <fileset dir="_bin" />     …     <manifest>         <attribute name="Main-Class" value="com.mypackage.ClassWithMain" />     </manifest> </jar> As you can see, we usee the ‘jar’ ant task to create a JAR file, we want to create the JAR file with the name ‘my-executable-jar.jar’ – which is given as ‘destfile’ attribute value of ‘jar’ task and we wanted to include all the compiled classes which are available at ‘_bin’ directory – which is provided using ‘fileset’ tag in the second line of the script. Then comes the important part – th...

JAR Dependency and Ant Jar Task [Merging Archives]

Ever had a situation where you are using Ant to build a JAR file and this JAR uses classes from other JAR OR needs few other JAR files to be in class path. Placing dependent JARs in class path manually is one way of doing it, but what if you want to generate/deliver/use only one JAR [may be executable] which includes all the dependent JARs in it. ‘ zipfileset ’ attribute of the ‘ jar ’ ANT task is the one to use. Say, you are trying to generate a JAR file with name ‘ my-application.jar ’, which needs/depends on another JAR with the name ‘ some-dependency.jar ’. Assuming all the compiled classes are available under ‘_bin’ directory, the dependent JAR is available under ‘lib’ directory and you want to place the generated JAR under ‘_dist’ directory, ANT script might look as given below <jar destfile="_dist/my-application.jar">     <fileset dir="_bin" />     <zipfileset src="lib/some-dependency.jar" includes="**/*.class" excludes=...

Ant Script To Sign A JAR File

To sign a JAR file you need a ‘keystore” first. You can create a sample keystore using the following simple command. keytool -genkey -keystore <filename.store> -alias <aliasname> After creating the keystore, you can add the following Ant tag to sign the JAR file using it. <signjar jar="<JAR file to be signed>" alias="<Keystore Alias Name>"                 keystore="<Keystorefile.store>" storepass="<Keystore password>"/> Attributes used are jar – The JAR file path which needs to be signed. alias – Keystore alias name, given in the ‘keytool’ command to create the keystore. keystore – Path to the keystore file, which was created using the ‘keytool’ command. storepass – Keystore password used while creating the keystore using ‘keytool’ command.