简体   繁体   English

如何在ant文件集或src中使用通配符

[英]How to use wild card in ant fileset or src

Using ant 1.5 I am trying to create a jar file with files compiled under product directory that can constantly change the build name 使用ant 1.5,我试图用产品目录下编译的文件创建一个jar文件,该文件可以不断更改构建名称

/target
   |---myapp-1.3.5-SNAPSHOT
          |--- WEB-INF
                 |---classes
                 |---i18n

It's kind of picky but I have to make a jar file that still keep the web structure 有点挑剔,但我必须制作一个仍然保持web结构的jar文件

|---myapp-utility.jar
       |--- WEB-INF
              |---classes
              |---i18n

That means I have to put wild card to identify the directory with build and snapshot 这意味着我必须使用通配符来标识带有构建和快照的目录

<jar destfile="myapp-utility.jar">
    <manifest>
        ....
    </manifest>
    <fileset dir="myapp-**/"/>
</jar>

and it doesn't work, wild card is not recognized. 并且它不起作用,无法识别通配符。 So what is the alternative? 那么替代品是什么?

Ant 1.5 is a very old version of Ant. Ant 1.5是Ant的非常旧的版本。 If you can use at least Ant 1.8.2 (released in 2010), you can use the following... 如果至少可以使用Ant 1.8.2(于2010年发布),则可以使用以下...

<jar destfile="myapp-utility.jar">
    <mappedresources>
        <fileset dir="target">
            <include name="myapp-*/**"/>
        </fileset>
        <cutdirsmapper dirs="1"/>
    </mappedresources>
</jar>

The <mappedresources> resource collection wraps the <fileset> element and then applies a mapper to the results. <mappedresources>资源集合包装<fileset>元素,然后将映射器应用于结果。

It's true that the dir of <fileset> can't handle wildcards. 的确, <fileset>dir无法处理通配符。 Luckily, <include> can handle wildcards. 幸运的是, <include>可以处理通配符。 So, the above puts the wildcard test into <include> . 因此,以上将通配符测试放入<include> The ** ensures all files under myapp-* are matched. **确保myapp-*下的所有文件都匹配。

Finally, <cutdirsmapper> removes the myapp-1.3.5-SNAPSHOT/ part from each file. 最后, <cutdirsmapper>从每个文件中删除myapp-1.3.5-SNAPSHOT/部分。

You can use pathconvert to analyze the wildcard specification: 您可以使用pathconvert分析通配符规范:

<pathconvert property="myapp.dir">
    <dirset dir="target" includes="myapp-*"/>
</pathconvert>

<jar destfile="myapp-utility.jar">
    <manifest>
        <!-- .... -->
    </manifest>
    <fileset dir="${myapp.dir}"/>
</jar>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM