1

<jar destfile="somefile" manifest="META-INF/MANIFEST.MF">

This script runs for multiple projects. Some of the projects have a manifest file, others don't. Build fails on a project that does not have a manifest file.

Is there a way to configure this jar task, so that ant uses project manifest file if it exists and generates a manifest file for a jarred project that doesn't have its own manifest?

mikemil
  • 1,213
  • 10
  • 21
user2984213
  • 119
  • 10

1 Answers1

0

Here's a sample I created. This has two jar tasks: jar and jar1. One uses the if check and the other the unless check. The ant target 'all' calls both, but only 1 should run. It checks if the manifest file exsts and if so uses that file, otherwise you can create a local in the jar1 task.

If you want to have only the 1 jar target, then you may need to use the Ant-Contrib tasks and use the tag. Here is a good link to review for this too.

<project name="StackOverflow" basedir="." default="all">

    <property name="src.dir" value="${basedir}/src"/>
    <property name="build.dir" value="${basedir}/build"/>
    <property name="classes.dir" value="${build.dir}/classes"/>

    <target name="all" depends="compile,jar,jar1"/>

    <target name="check-manifest">
        <available file="META-INF/MANIFEST.MF" property="manifest.present"/>
    </target>

    <target name="jar" depends="check-manifest" if="manifest.present">
        <echo>Using existing manifest.mf</echo>
        <jar destfile="hello.jar" manifest="META-INF/MANIFEST"/>
    </target>

    <target name="jar1" depends="check-manifest" unless="manifest.present">
        <echo>creating local manifest</echo>
        <jar destfile="hello.jar">
            <manifest>
                <attribute name="Built-By" value="${user.name}"/>
                <attribute name="Permissions" value="all-permissions"/>
                <attribute name="Codebase" value="*"/>
            </manifest>
            <fileset dir="${classes.dir}">
                <include name="**/*.*"/>
            </fileset>
        </jar>
    </target>

</project>
Community
  • 1
  • 1
mikemil
  • 1,213
  • 10
  • 21