xml – maven-jar-plugin包含vs排除

我有一个现有的pom文件,其中包含一个maven-jar-plugin部分.它运行测试jar目标,目前不包括几个目录:
<excludes>
     <exclude>...</exclude>
     <exclude>...</exclude>
     <exclude>somedir/**</exclude>
 </excludes>

我需要在somedir目录中包含一个文件,但遗漏somedir目录中的其余文件.我已经读过,包括优先于排除,所以我添加了类似下面的内容(之前没有包含部分):

<includes>
    <include>somedir/somefile.xml</include>
</includes>

这最终会创建一个jar文件进行测试,其中只有几个文件(只是meta-inf中的东西).我包含的文件也不在jar中.我期望的是一个jar,它与我在包含一个额外文件的更改之前创建的jar相同.

在这里想念的是什么?

首先,如果你没有指定任何包含,那么maven jar插件将使用** / **作为认模式(参见 o.a.m.p.j.AbstractJarMojo),即它将包括所有内容.如果您覆盖此认模式,插件显然只会包含您告诉他包含的内容.

其次,目录扫描最后由o.c.p.u.DirectoryScanner完成,这就是该类的javadoc所说的:

 * The idea is simple. A given directory is recursively scanned for all files
 * and directories. Each file/directory is matched against a set of selectors,* including special support for matching against filenames with include and
 * and exclude patterns. Only files/directories which match at least one
 * pattern of the include pattern list or other file selector,and don't match
 * any pattern of the exclude pattern list or fail to match against a required
 * selector will be placed in the list of files/directories found.

因此,使用当前包含和排除模式的集合,只有一个文件将与包含模式匹配,但也匹配排除模式,因此不会被选中,并且您将得到一个几乎为空的存档(仅使用认清单,请参阅o.a.m.p.j.AbstractJarMojo#createArchive()).

我不能在这里给你确切的解决方案,但你显然需要重新考虑包含/排除文件的方式(例如添加更多包含模式,删除< exclude> somedir / **< / exclude>或仅使用包含,或仅使用排除).

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念