【问题标题】:Copy files and folder to WEB-INF using Ant使用 Ant 将文件和文件夹复制到 WEB-INF
【发布时间】:2013-09-12 08:18:35
【问题描述】:

我想将 .properties 文件从某个位置复制到我的 WEB-INF/classes/com/infiniti 文件夹(在 WAR 文件中)。

我已经浏览了这个链接How to get Ant to copy properties file to classes directory 使用它我可以将 .properties 文件复制到 WEB-INF/classes/ 但不能复制到 WEB-INF/classes/com/infiniti

我使用的代码是:

<war destfile="${deploy}/acc.war" webxml="${warSrc}/web/WEB-INF/web.xml">
            <lib dir="${lib}">
.......
.......
.......
            <classes dir="${configHome}/config/com/infiniti">
                <include name="accredit.properties" />
            </classes>

...
....
.......
</war>

我还需要将 ${configHome}/resources/com/infiniti/errorcode 文件夹复制到 WEB-INF/classes/com/infiniti.

这可以使用 Ant 实现吗?

【问题讨论】:

    标签: ant copy war


    【解决方案1】:

    是的,你可以像这样使用ZipFileSet

    <war destfile="${deploy}/acc.war" webxml="${warSrc}/web/WEB-INF/web.xml">
    ...
        <zipfileset dir="${configHome}/config/com/infiniti" includes="**/*.properties" prefix="WEB-INF/classes/com/infiniti"/>
    

    【讨论】:

    • 非常感谢 Michele...您每天为我节省了 2 小时的任务 :)...它工作顺利...也适用于我的问题的第二部分(复制文件夹).. .我用过这个
    【解决方案2】:

    是的,可以使用 ant。只需使用复制或同步命令来移动您的文件:

    <copy todir="${distribution}/location" file="${local.path}/data/file.txt">
    </copy>
    

    你也可以用规则复制:

    <copy includeemptydirs="false" todir="${combined.bin}">
      <fileset dir="${buildbin}"/>
      <fileset dir="${output2buildbin}"/>
      <fileset dir="${output3buildbin}"/>
    </copy>
    

    使用同步:

    <sync includeemptydirs="false" todir="${distres}">
      <fileset dir="${buildres}">
        <include name="logging/**" />
      </fileset>
    </sync>
    

    他们的文档网站上描述了任务:

    http://ant.apache.org/manual/Tasks/copy.html

    同样的“文件集”声明适用于战争任务:

    Examples
    
    Assume the following structure in the project's base directory:
    
    thirdparty/libs/jdbc1.jar
    thirdparty/libs/jdbc2.jar
    build/main/com/myco/myapp/Servlet.class
    src/metadata/myapp.xml
    src/html/myapp/index.html
    src/jsp/myapp/front.jsp
    src/graphics/images/gifs/small/logo.gif
    src/graphics/images/gifs/large/logo.gif
    
    then the war file myapp.war created with
    
    <war destfile="myapp.war" webxml="src/metadata/myapp.xml">
      <fileset dir="src/html/myapp"/>
      <fileset dir="src/jsp/myapp"/>
      <lib dir="thirdparty/libs">
        <exclude name="jdbc1.jar"/>
      </lib>
      <classes dir="build/main"/>
      <zipfileset dir="src/graphics/images/gifs"
                  prefix="images"/>
    </war>
    
    will consist of
    
    WEB-INF/web.xml
    WEB-INF/lib/jdbc2.jar
    WEB-INF/classes/com/myco/myapp/Servlet.class
    META-INF/MANIFEST.MF
    index.html
    front.jsp
    images/small/logo.gif
    images/large/logo.gif
    

    http://ant.apache.org/manual/Tasks/war.html

    【讨论】:

    • 我尝试了复制,但似乎战争标签下不支持复制....在使用 时给了我这个错误'战争不支持嵌套的“复制”元素”
    • 它应该支持文件集。查看文档中的示例。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-20
    • 2018-10-22
    • 2013-11-19
    • 2019-09-19
    • 2019-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多