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.
Since Ant 1.8.0 there is a new resource collection -
mappedresources
that can be used in place of thewar
tasklib
element.So, the task might look like this (pretty much straight from the docs):
This feature was added to resolve a long-standing feature request to make the task flatten jars when deploying to
WEB-INF/lib
.previous answer:
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:
Another possibility is to use the ant-contrib
pathtofileset
task.Another solution, possibly 'not the best' will be to place required jar file in WEB-INF/lib, and then set the classpath from there.
When its time to build the war, you need not worry about the
<lib>
at all, as jars are already placed in WEB-INF/lib folder.