如何在使用Ant构建脚本创建WarFile时在WEB-INF / lib文件夹中包含Classpath jar

时间:2014-12-12 21:13:16

标签: java eclipse ant build

正致力于创建用于构建和部署项目的ant脚本。项目结构如下:

    Projectname
    --src
    --tst
    --lib ( I have 5 jars here)
    --resources
    --WebContent
          --META-INF
          --WEB-INF
               --lib (I have 3 jars here)
               --properties
               --templates
               --stylesheets
               --web.xml

当我使用ant脚本创建war文件时,war文件的结构应如下所示:

--WEB-INF
    --classes
    --lib (should contain all the jar files from the entire project. ie, jars from the lib folders of the project and also the classpath)
--META-INF
    --MANIFEST.MF

但是当我构建项目时,创建的war文件具有以下不正确的结构,我希望结构与上面的结构类似。

--WEB-INF
   --classes
   --lib( is containing the jars that are in the lib folders of the project but it should also contain the classpath jars)
--META-INF
  --MANIFEST.MF
--abc.jar { These are the classpath jars that should also be in the WEB-INF/lib folder but they are not)
--xyz.jar
--mnf.jar
--qrs.jar


Here is the code snippet am using to create the WAR file in the build.xml file.
<target name="war" description="Bundles the application as a WAR file" depends="build">
        <echo> === PACKAGE WAR ====== </echo>
         <delete dir="target" failonerror="false"/>
         <mkdir dir="target"/>
        <war destfile="target/test.war" needxmlfile="false" >
            <fileset dir="WebContent">
                <include name="**/*.*"/>
            </fileset>
            <path>  
            <path refid="MobileServices.classpath"/>
            <fileset dir="${lib.dir}" includes="**/*.jar">
            </fileset>          
            </path> 
            <classes dir="WebContent/WEB-INF/classes"/>
        </war>

使用<path refid="> to include the classpath jars in the warfile. Anyhelp非常感谢。

1 个答案:

答案 0 :(得分:1)

而不是使用 &lt; fileset dir =&#34; $ {lib.dir}&#34;包括=&#34; ** / *罐子&#34;&GT;

&LT; /文件集&GT;

尝试

&lt; lib dir =&#34; $ {lib.dir}&#34;包括=&#34; ** / *罐子&#34;&GT;

&LT; / lib中&GT;

并将其移到路径标记之外。

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