Ant脚本:在javac的类路径战争lib中的JAR prevent重复 [英] Ant script: Prevent duplication of JAR in javac-classpath war-lib
问题描述
我有一个ANT脚本,我有很多重复的路径相同的一组JAR文件。
但在classpath中,并在战争中的元素这么多双措辞。
I have a ANT script and I have a lot of duplicated path to same set JAR files. But there is so many double wording in the classpath and also in the war element.
<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>
我要总结他们到一个列表,它是更容易保持更新。
I want to summary them into ONE list which is easier to keep update.
但我阻止,因为我不知道如何与一个文件集样结构共享的路径样结构。
But I am blocked as I have no idea how to share a path-like-structure with a fileset-like-structure.
推荐答案
由于蚂蚁1.8.0有一个新的资源集合 - <一个href=\"http://ant.apache.org/manual/Types/resources.html#mappedresources\"><$c$c>mappedresources$c$c>那
来代替战
任务使用 LIB
元素。
Since Ant 1.8.0 there is a new resource collection - mappedresources
that
can be used in place of the war
task lib
element.
因此,任务可能是这样的(pretty多少直接从文档):
So, the task might look like this (pretty much straight from the docs):
<war ... >
<mappedresources>
<restrict>
<path refid="my.classpath"/>
<type type="file"/>
</restrict>
<chainedmapper>
<flattenmapper/>
<globmapper from="*" to="WEB-INF/lib/*"/>
</chainedmapper>
</mappedresources>
</war>
中添加了此功能href=\"https://issues.apache.org/bugzilla/show_bug.cgi?id=31947\">解决使
部署到 WEB-INF / lib目录
。当任务压扁罐子
的 previous答案:的
虽然不能很容易地转换与香草的Ant文件集的路径,你可以走另外一条路。
所以,其中一个选项是在文件集来定义你的罐子,并从中获得的路径。
事情是这样的可能:
Although you can't easily convert a path to a fileset with vanilla Ant, you can go the other way. So one option would be to define your jars in a fileset, and derive the path from it. Something like this perhaps:
<fileset id="my.fileset" dir="${basedir}">
<include name="folderA/subFolderA/1.0/A.jar"/>
<include name="folderC/subFolderB/1.0/B.jar"/>
<include name="folderF/subFolderZ/2.0/Z.jar"/>
<include name="moreFolderF/subFolderZ/2.0/additionFile.jar"/>
<include name="moreFolderF/subFolderZ/2.0/additionRuntimeFile.jar"/>
</fileset>
<path id="my.classpath">
<fileset refid="my.fileset" />
</path>
<!-- javac stays the same -->
<war ...>
<lib refid="my.fileset" />
</war>
另一种可能性是使用蚂蚁的contrib pathtofileset
任务。
这篇关于Ant脚本:在javac的类路径战争lib中的JAR prevent重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!