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

最后都变了- 提交于 2019-12-12 18:27:34

问题


Consider the following directory structure:

./source/com/mypackage/../A.java
./extensions/extension1/source/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?


回答1:


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>


来源:https://stackoverflow.com/questions/2794084/how-to-jar-java-source-files-from-different-sub-directories

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!