Dropwizard is an amazing framework for anyone who wishes to build web services, and I heartily recommend it. However, for those sitting behind closed corporate intranets without any proxy Maven repositories, it can prove to be a bit of a hassle to set up.

Firstly, one has to transitively follow the dependencies and download the dependent JARs. This shouldn’t be much of an issue, it’s just tedious. The more interesting issue that I encountered was the exclusion of digital signatures from signed JARs while writing an Ant script.

My initial attempt was to add the file pattern as an exclusion attribute for the zipgroupfileset task. However, it seems that there’s no way to filter files when using zipgroupfileset as the include/excludes applies to the zips to be merged, not the content within them. After some consultation with a developer’s best friend, I came across the following solution:

<jar jarfile="dist/external-libs.jar" filesetmanifest="mergewithoutmain">
  <zipgroupfileset dir="lib/">
    <include name="**/*.jar"/>
  </zipgroupfileset>
</jar>
<sleep seconds="1"/>
<jar jarfile="${dist}/lib/historadar-${DSTAMP}.jar" filesetmanifest="mergewithoutmain">
  <manifest>
    <attribute name="Main-Class" value="com.example.helloworld"/>
    <attribute name="Class-Path" value="."/>
  </manifest>
  <fileset dir="classes/"/>
  <zipfileset src="dist/external-libs.jar">
    <exclude name="**/*.SF"/>
  </zipfileset>
</jar>

Assuming that one has already compiled the classes to the classes/ directory, the first jar task then puts all the jars it finds in lib/ into external-libs.jar. It then waits for one second to avoid getting warnings about the files having modification dates in the future. Next, the second jar task merges my class files from the classes/ directory with the content of external-libs.jar while excluding all digital signatures from the signed JARs.

With this, one should be able to build an executable Dropwizard JAR via Ant.