Ant: construct manifest classpath 

Joined:
04/09/2007
Posts:
703

October 01, 2008 03:01:07    Last update: October 01, 2008 17:17:11
This ant script collects all jar file names from the lib directory and generate the Class-Path to be used in the MANIFEST file for a jar task. There's no need to set CLASSPATH separately when the jar files in the lib folder are jared together with the target jar.
<project name="manifest_demo" basedir="." default="gen-manifest">
    <target name="gen-cp" description="Generate CLASSPATH to use in manifest">
        <pathconvert dirsep='${file.separator}' property="full-lib-dir">
            <path>
                 <pathelement path="lib"/>
            </path>
        </pathconvert>

        <echo>full-lib-dir: ${full-lib-dir}</echo>

        <pathconvert pathsep=" " dirsep="/" property="manifest-path">
            <path>
                <fileset dir="lib" includes="*"/>
            </path>
            <map from="${full-lib-dir}${file.separator}" to=""/>
        </pathconvert>

        <echo>manifest-path: ${manifest-path}</echo>
    	
        <pathconvert pathsep=" " dirsep="/" property="war-manifest-path">
            <path>
                <fileset dir="lib" includes="*"/>
            </path>
            <map from="${full-lib-dir}${file.separator}" to="lib/"/>
        </pathconvert>

        <echo>war-manifest-path: ${war-manifest-path}</echo>
    </target>

    <target name="gen-manifest" depends="gen-cp" description="Generate a manifest file">
        <manifest file="MANIFEST.MF">
            <attribute name="Built-By" value="${user.name}"/>
            <attribute name="Class-Path" value="${war-manifest-path}"/>
        </manifest>
    </target>
</project>
Share |
| Comment  | Tags
 
Easy email testing with http://www.ximailstop.com