开发者

How to jar java source files from different (sub-)directories?

开发者 https://www.devze.com 2022-12-30 03:01 出处:网络
Consider the following directory structure: ./source/com/mypackage/../A.java ./extensions/extension1/s开发者_如何学运维ource/com/mypackage/../T.java

Consider the following directory structure:

./source/com/mypackage/../A.java
./extensions/extension1/s开发者_如何学运维ource/com/mypackage/../T.java
./extensions/extension2/source/com/mypackage/../U.java
...
./extensions/extensionN/source/com/mypackage/../Z.java

I want to produce a source jar with the following contents:

com/mypackage/../A.java
com/mypackage/../T.java
com/mypackage/../U.java
...
com/mypackage/../Z.java

I know I could use a fileset for each source directory. But is there an easy solution using ANT without having to refer to all extensions explicitly?


How about flattening all the files to be included in the archive into a single directory structure, then archiving from there?

Use a regexpmapper to do the flatten during copy, something like this:

<delete dir="merged" />
<mkdir dir="merged" />

<copy todir="${basedir}/merged">
    <fileset dir="${basedir}">
        <include name="source/**"/>
        <include name="extension*/**"/>
    </fileset>
    <regexpmapper from=".*source/(.*)" to="\1" />
</copy>

<jar destfile="mypackage.jar" filesonly="yes">
    <fileset dir="merged">
        <include name="**" />
    </fileset>
</jar>
0

精彩评论

暂无评论...
验证码 换一张
取 消