使用ant运行build.xml后,MANIFEST.MF被覆盖

时间:2012-08-31 05:38:06

标签: ant build manifest.mf

具有以下目录结构

src/com
src/META-INF/MANIFEST.MF
src/META-INF/spring
src/META-INF/spring/context.xml

现在当我运行脚本时,我的清单文件被覆盖,我不希望这样,因为我必须在其中添加自定义输入,我希望它添加生成的.jar文件。这是所有其他文件都被复制,但这一个是覆盖。

我的build.xml如下

<project name="TaskNodeBundle" default="all" basedir=".">
    <!-- Sets variables which can later be used. -->
    <!-- The value of a property is accessed via ${} -->
    <property name="bundlename" value="tasknodebundle" />
    <property name="src.dir" location="../src" />
    <property name="lib.dir" location="../lib" />
    <property name="build.dir" location="/buildoutput" />
    <property name="build.dest" location="../build/dest" />


    <!--
    Create a classpath container which can be later used in the ant task
  -->
    <path id="classpath">
        <fileset dir="${lib.dir}/">
            <include name="*.jar" />

        </fileset>
    </path>

    <target name="clean">
            <delete dir="${build.dir}" />
            <delete dir="${build.dest}" />
    </target>


    <!-- Deletes the existing build directory-->
    <target name="mkdir" depends="clean">
            <mkdir dir="${build.dest}"/>
    </target>


<!-- Compiles the java code -->
    <target name="compile" depends="mkdir">
        <javac srcdir="${src.dir}" destdir="${build.dest}" classpathref="classpath" />
    </target>

    <target name="package-bundle" depends="compile" description="Generates the bundle">
        <jar destfile="${build.dest}/${bundlename}.jar">
            <fileset dir="${src.dir}">
                <include name="**/**.class" />
                <include name="**/**.properties"/>
                <include name="/META-INF/**.*" />
                <include name="/META-INF/spring/**.*" />
            </fileset>

        </jar>
    </target>


    <target name="all" depends="package-bundle">
    </target>

</project>

1 个答案:

答案 0 :(得分:3)

请参阅http://ant.apache.org/manual/Tasks/jar.html

  

如果省略manifest,Apache将提供一个简单的。{1}}   蚂蚁。

只需添加manifest属性或使用zip任务。

另外,ant路径掩码使用不正确。请参阅http://en.wikibooks.org/wiki/Apache_Ant/Fileset

更正版本:

    <zip destfile="${build.dest}/${bundlename}.jar">
        <fileset dir="${src.dir}">
            <include name="META-INF/**" />
            <include name="**/*.class" />
            <include name="**/*.properties"/>
        </fileset>
    </zip>