用ANT根据包名动态生成JAR文件 [英] Dynamically generate JAR files based on package name with ANT

查看:26
本文介绍了用ANT根据包名动态生成JAR文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的构建文件有以下重复性任务:

My current build file has the following repetitive tasks:

<jar jarfile="${build.lib}/${prefix}-foo.jar">
    <fileset dir="${build.classes}">
        <include name="com/a/c/foo/**"/>
    </fileset>  
</jar>
<jar jarfile="${build.lib}/${prefix}-bar.jar">
    <fileset dir="${build.classes}">
        <include name="com/a/c/bar/**"/>
    </fileset>
</jar>

...等问题是必须为每个新包或每个新子项目修改 build.xml.这在我工作的地方经常发生.

... etc. The issue is that the build.xml must be modified for each new package or for each new sub-project. This is a frequent occurrence where I work.

我想将其替换为基于根"包动态生成 JAR 及其文件名的逻辑.因此,例如,我可以将根包设置为 com/a/c,并且该包下的所有包都将获得自己的 JAR.请注意,foo"或bar"下的所有包都只是foo.jar"或bar.jar"的一部分.

I would like to replace this with logic that will dynamically generate the JARs and their file names based off of a "root" package. So, for example, I could set the root package to be com/a/c, and all packages directly under that package would get their own JAR. Note that all packages under "foo" or "bar" would just be part of "foo.jar" or "bar.jar".

我查找了 ANT 的循环逻辑任务.我在每个 ant-contrib 和 JWare/AntXtras 中都找到了一个,但我无法按预期工作.

I looked up for loop logic tasks for ANT. I found one in each ant-contrib and JWare/AntXtras, but I could not get either to work as desired.

推荐答案

我不知道循环和查找所有包名称,但您可以使用宏来避免代码重复.

I don't know about looping over and finding all package names, but you could use a macro to avoid code duplication.

我没试过这个,但它可以工作

I haven't tried this, but it could work

<macrodef name="build_jar">
    <attribute name="name"/>
    <sequential>
        <jar jarfile="${build.lib}/${prefix}-@{name}.jar">
            <fileset dir="${build.classes}">
                <include name="com/a/c/@{name}/**"/>
            </fileset>
        </jar>
    </sequential
</macrodef>

<target name="build_foo">
    <build_jar name="foo"/>
</target>

<target name="build_bar">
    <build_jar name="bar"/>
</target>

这篇关于用ANT根据包名动态生成JAR文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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