Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant: Exclude files from merged jar file

Tags:

For a java project I'd like to merge all third-party jars it depends on into the main jar created by Apache Ant, which I already managed to do.

The problem is that some of these jar-files have signature-files in their META-INF-directories, so when I try to run my jar-file, I get the error message "Invalid signature file digest for Manifest main attributes". After I delete the signature-files manually the error is gone.

I tried to filter the signature files out in my ant-file with an excludes-attribute or an exclude-tag, but nothing seems to have any effect.

This is the ant-task:

<target name="jar" description="Creates the jar file">
  <mkdir dir="${jar}"/>
  <jar destfile="${jar}/${ant.project.name}.jar" level="9" filesetmanifest="mergewithoutmain">
    <zipgroupfileset dir="${lib}" includes="*.jar"/>
    <zipfileset dir="${class}"/>
    <manifest>
      <attribute name="Main-Class" value="${mainclass}"/>
    </manifest>
  </jar>
</target>

How can I filter files from the resulting jar in this ant-task? Thanks for your help!