如何使用ANT构建一个包含任意自定义类路径的WAR

如何使用ANT构建一个包含任意自定义类路径的WAR,ant,war,Ant,War,我必须从ANT脚本构建一个WAR文件。我声明了一个文件集,其编译类路径由任意库组成(在下面的示例中,它们只有2个。在我的实际情况中,最多90个)。我希望在war中包含相同的库集,而不必在两个位置声明它们:在和任务中 这是我的ANT脚本: <project name="war-with-custom-classpath" basedir="."> <property environment="env" /> <property name="lib"

我必须从ANT脚本构建一个WAR文件。我声明了一个
文件集
,其编译类路径由任意库组成(在下面的示例中,它们只有2个。在我的实际情况中,最多90个)。我希望在war中包含相同的库集,而不必在两个位置声明它们:在
任务中

这是我的ANT脚本:

<project name="war-with-custom-classpath" basedir=".">

    <property environment="env" />
    <property name="lib" location="${env.USERPROFILE}/.m2/repository" />
    <fileset id="my.classpath" dir="${lib}">
        <include name="commons-pool/commons-pool/1.5.6/commons-pool-1.5.6.jar" />
        <include name="commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar" />
    </fileset>

    <target name="compile">
        <javac srcdir="src/test/java" classpathref="my.classpath">
        </javac>
    </target>

    <target name="war">
        <delete file="mywar.war" />
        <war destfile="mywar.war" needxmlfile="false">
            <lib refid="my.classpath">
            </lib>
        </war>
        <!--Read the created war to see its contents-->
        <exec command="jar ft mywar.war">
        </exec>
    </target>

</project>
是否有任何形式的将罐子从其路径上剥离后包括在内?像这样:

META-INF/
META-INF/MANIFEST.MF
WEB-INF/
WEB-INF/lib/
WEB-INF/lib/commons-logging-1.1.1.jar
WEB-INF/lib/commons-pool-1.5.6.jar
我已经试过了:

<lib refid="my.classpath" prefix="/WEB-INF/lib"/>
。。。但它会启用错误
只能为指定单个文件的文件集指定完整路径属性。

我也在和中进行了研究,但到目前为止还没有《财富》。

考虑使用一个包含一个的。链映射器依次包含一个后跟一个


替换任务中的

中的文件路径中删除目录。
将目录添加回

至少需要Ant 1.8

<lib refid="my.classpath" prefix="/WEB-INF/lib"/>
<lib refid="my.classpath" fullpath="WEB-INF/lib"/>
<lib refid="my.classpath" fullpath="/WEB-INF/lib"/>
<zipfileset refid="my.classpath" fullpath="WEB-INF/lib" />
<war destfile="mywar.war" needxmlfile="false">
    <mappedresources>
        <fileset refid="my.classpath" />
        <chainedmapper>
            <flattenmapper/>
            <globmapper from="*.jar" to="WEB-INF/lib/*.jar" />
        </chainedmapper>
    </mappedresources>
</war>