用Ant打包java project,自动生成manifest文件。
<?xml version="1.0" encoding="UTF-8"?> <project name="Alab" default="" basedir="" > <property name="project.path" value="../"/> <property name="src.home" value="${project.path}/src" /> <property name="lib.home" value="${project.path}/lib" /> <property name="build.home" value="${project.path}/bin" /> <property name="dist.home" value="${project.path}/dist" /> <property name="config.file" value="${project.path}/config.xml" /> <property name="jar.name" value="Alab.jar" /> <property name="mainclass" value="net.vnote.alab.AlabDaemon" /> <property name="build.date" value="20121106" /> <property name="component.name" value="alab" /> <property name="component.version" value="1.0.0" /> <property name="component.vendor" value="vnote.net" /> <target name="clean" description="clean"> <delete dir="${build.home}" includeEmptyDirs="true" /> <delete dir="${dist.home}" includeEmptyDirs="true" /> </target> <target name="initial" description="initialization"> <mkdir dir="${build.home}" /> <mkdir dir="${dist.home}" /> </target> <target name="compile" depends="initial" description="compile"> <javac srcdir="${src.home}" destdir="${build.home}" debug="on" optimize="on" deprecation="on" extdirs="${lib.home}" /> </target> <target name="jar" depends="compile" description="Create jar and MANIFEST.MF"> <pathconvert property="libs.project" pathsep=" "> <mapper> <chainedmapper> <!-- remove absolute path --> <flattenmapper /> <!-- add lib/ prefix --> <globmapper from="*" to="lib/*" /> </chainedmapper> </mapper> <path> <fileset dir="${lib.home}"> <include name="**/*.jar" /> </fileset> </path> </pathconvert> <jar jarfile="${dist.home}/${jar.name}" basedir="${build.home}" excludes="log4j.properties"> <manifest> <attribute name="Main-Class" value="${mainclass}" /> <section name="common"> <attribute name="Specification-Title" value="${component.name}" /> <attribute name="Specification-Version" value="${component.version}" /> <attribute name="Specification-Vendor" value="${component.vendor}" /> <attribute name="Implementation-Title" value="${component.name}" /> <attribute name="Implementation-Version" value="${component.version} ${build.date}" /> <attribute name="Implementation-Vendor" value="${component.vendor}" /> </section> <attribute name="Class-Path" value="${libs.project}" /> </manifest> </jar> </target> <target name="distribute" depends="jar" description="Copy jar and resource to the dist.home"> <copy todir="${dist.home}/lib"> <fileset dir="${lib.home}" excludes="CVS" /> </copy> <copy todir="${dist.home}"> <fileset file="${config.file}"/> </copy> </target> </project>