Ant 更改 war 文件中的目录结构

Ant change directory structure in the war file

我是 ant 的新手,我必须将我的 web 项目包装在 war 文件中,我正在使用 ant 我的项目结构如下:

myproject
--images
--css
--js

在 war 文件中,最终结构如下:

myproject
--css
--images
--js
--META-INF
--WEB-INF

我想更改最终结构(将项目目录中的所有内容都放在 "public" 文件夹中)但仅在 war 文件中,我想像那样:

myproject
--public
-----css
-----images
-----js
--META-INF
--WEB-INF

我尝试过使用复制任务和移动任务但没有成功... 我应该怎么做才能做到这一点?

我认为在 zipfileset 中使用 prefix 属性可能会对您有所帮助(参见 zipfileset):

<target name="Wrappin the in war file" description="Compiling....">
    <mkdir dir="${build-directory}" />
    <delete file="${build-directory}/${war-file-name}" />
    <war warfile="${build-directory}/${war-file-name}" webxml="${web-xml-file}">
        <zipfileset dir="${web-directory}" prefix="public">
            <exclude name=".git/**" />
            <exclude name=".svn/**" />
            <exclude name=".idea/**" />
            <exclude name="node_modules/**" />
            <exclude name="bower_components/**" />
        </zipfileset>
        <manifest>
            <attribute name="Built-By" value="${builder}" />
            <attribute name="Built-On" value="${build-info.current-date}" />
            <attribute name="Built-At" value="${build-info.current-time}" />
        </manifest>
    </war>
</target>