简体   繁体   English

如何从不同(子)目录中提取Java源文件?

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

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: 我想产生一个包含以下内容的源jar:

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? 但是是否有使用ANT而不需要显式引用所有扩展的简单解决方案?

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: 在复制过程中使用regexpmapper进行展平,如下所示:

<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>

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

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