Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ant脚本:防止javac类路径库中JAR的重复_Ant_War - Fatal编程技术网

Ant脚本:防止javac类路径库中JAR的重复

Ant脚本:防止javac类路径库中JAR的重复,ant,war,Ant,War,我有一个ANT脚本,并且有很多到相同的SETJAR文件的重复路径。 但是在类路径和war元素中有很多双重措辞 <path id="my.classpath"> <pathelement location="folderA/subFolderA/1.0/A.jar"/> <pathelement location="folderC/subFolderB/1.0/B.jar"/> <pathelement location="folderF/su

我有一个ANT脚本,并且有很多到相同的SETJAR文件的重复路径。 但是在类路径和war元素中有很多双重措辞

<path id="my.classpath">
  <pathelement location="folderA/subFolderA/1.0/A.jar"/>
  <pathelement location="folderC/subFolderB/1.0/B.jar"/>
  <pathelement location="folderF/subFolderZ/2.0/Z.jar"/>
  <pathelement location="compile/subFolderX/1.0/onlyForJavac.jar"/>
</path>
....
<javac ...>
 <classpath refid="my.classpath" />
</javac>
....
<war ...>
 <lib file="folderA/subFolderA/1.0/A.jar"/>
 <lib file="folderC/subFolderB/1.0/B.jar"/>
 <lib file="folderF/subFolderZ/2.0/Z.jar"/>
 <lib file="moreFolderF/subFolderZ/2.0/additionFile.jar"/>
 <lib file="moreFolderF/subFolderZ/2.0/additionRuntimeFile.jar"/>
</war>

....
....
我想将它们汇总到一个列表中,以便随时更新


但是我被阻止了,因为我不知道如何将类似路径的结构与类似文件集的结构共享。

自从Ant 1.8.0以来,出现了一个新的资源集合-它 可以用来代替
war
task
lib
元素

因此,任务可能如下所示(从文档中可以直接看出):


另一种可能是使用.

另一种解决方案,可能“不是最好的”是将所需的jar文件放在WEB-INF/lib中,然后从那里设置类路径

<path id="compile.classpath">
    <fileset dir="${lib.dir}" includes="*.jar"/>
</path>

当构建war时,您根本不需要担心
,因为JAR已经放在WEB-INF/lib文件夹中

<war destfile="${dist.dir}/${project.name}.war" webxml="${web.dir}/WEB-INF/web.xml">
        <fileset dir="${web.dir}"/>
        <classes dir="${build.dir}/classes"/>
    </war>

有个问题,它确实在WAR/WEB-INF/lib/@Dennis下创建了子文件夹-我更新了答案。我以前不知道WEB-INF/lib“非扁平化”的问题。
<path id="compile.classpath">
    <fileset dir="${lib.dir}" includes="*.jar"/>
</path>
<war destfile="${dist.dir}/${project.name}.war" webxml="${web.dir}/WEB-INF/web.xml">
        <fileset dir="${web.dir}"/>
        <classes dir="${build.dir}/classes"/>
    </war>