Ant 脚本:防止在 javac-classpath war-lib 中重复 JAR [英] Ant script: Prevent duplication of JAR in javac-classpath war-lib

查看:27
本文介绍了Ant 脚本:防止在 javac-classpath war-lib 中重复 JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ANT 脚本,而且我有很多相同的 JAR 文件的重复路径.但是在类路径和战争元素中有很多双重措辞.

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.

推荐答案

自 Ant 1.8.0 以来,有一个新的资源集合 - mappedresources可以用来代替 war 任务 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.

因此,任务可能看起来像这样(几乎直接来自文档):

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>

添加此功能是为了解决长期存在的功能请求使任务在部署到 WEB-INF/lib 时压平 jar.

This feature was added to resolve a long-standing feature request to make the task flatten jars when deploying to WEB-INF/lib.

上一个答案:

虽然您无法使用 vanilla Ant 轻松地将路径转换为文件集,但您可以采用另一种方式.因此,一种选择是在文件集中定义您的 jar,并从中导出路径.大概是这样的:

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>

另一种可能性是使用 ant-contrib pathtofileset 任务.

Another possibility is to use the ant-contrib pathtofileset task.

这篇关于Ant 脚本:防止在 javac-classpath war-lib 中重复 JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆