基于与ANT包名动态生成JAR文件 [英] Dynamically generate JAR files based on package name with ANT

查看:359
本文介绍了基于与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.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循环逻辑的任务。我发现一个在每个蚂蚁的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.

推荐答案

我不知道遍历和查找所有包的名字,但你可以使用宏来避免code重复。

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天全站免登陆