【问题标题】:Maven exclude folder not workingMaven排除文件夹不起作用
【发布时间】:2015-05-26 04:08:14
【问题描述】:

我的 pom 文件有如下代码: 我需要的地方应该排除在构建项目时生成给定文件,而 在构建项目时应排除生成给定文件夹(包括所有子文件夹和文件)本身。

<profile>
    <id>nets</id>
    <properties>
        <ulysses.menu>ldms-menu.properties</ulysses.menu>
        <approval.workflow>false</approval.workflow>
        <mail.useldap>false</mail.useldap>
        <mail.latize.usesmtp>false</mail.latize.usesmtp>
        <ulysses.base.uri>http://data.latize.com/nets</ulysses.base.uri>
        <!-- lee.menu>nets-menu.properties</lee.menu >
        <lee.ftl>nets.ftl</lee.ftl>
        <path.has.lee>nets</path.has.lee>
        <kiwi.pages.startup>core/nets/summary.html</kiwi.pages.startup>
        <project.exclude.core.files>**/marmotta/platform/core/services/triplestore/*SesameServiceImpl*.*</project.exclude.core.files-->
        <project.exclude.core.files>**/ihg*.*</project.exclude.core.files>
        <project.exclude.core.folder>**/web/ihg/**</project.exclude.core.folder>
    </properties>
</profile>

...
<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <excludes>
                    <!--excludes native sesame implementation-->
                    <!--exclude>**/PrimarySesameServiceImpl*.*</exclude>
                    <exclude>**/ApprovalSesameServiceImpl*.*</exclude>
                    <exclude>**/SesameServiceImpl*.*</exclude-->

                    <!--excludes GraphDB sesame implementation -->
                    <!--exclude>**/GraphDBPrimarySesameServiceImpl*.*</exclude>
                    <exclude>**/GraphDBApprovalSesameServiceImpl*.*</exclude>
                    <exclude>**/GraphDBSesameServiceImpl*.*</exclude-->

                    <exclude>${project.exclude.core.files}</exclude>
                </excludes>
                <resource>
                    <directory>${project.exclude.core.folder}</directory>
                    <excludes>
                        <exclude>*.*</exclude>
                    </excludes>
                </resource>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>test-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

这里从 ihg 开始的文件排除工作正常,但文件夹 ihg 没有被排除。我不知道在这种情况下如何排除文件夹。

【问题讨论】:

  • iirc, project.exclude.core.folders 不是 Maven 的内置属性。您应该向我们展示您是如何使用这些属性的。
  • @AdrianShum:在这种情况下,如何在我的代码层次结构中排除文件夹?我是 POM 的新手
  • “排除”是什么意思?从 Java 编译器中排除?排除资源捆绑?请具体。简而言之,尝试了解哪个插件正在处理您要排除的源代码,并从其项目页面中找到答案
  • @AdrianShum:我只是不想在构建项目时创建这些文件
  • 你能再试试看cmets吗?你错过了最重要的一点。除非您提供有关这些源代码的信息,否则没有人知道如何排除。

标签: java eclipse maven pom.xml


【解决方案1】:

maven-jar-plugin 中进行了简短的尝试。假设我有这样的事情:

foo-proj
  + src
    + main
      + resources
        + foo
          - foo.txt
        + bar
          - bar.txt

我可以通过以下方式从结果 jar 中排除 foo

<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <excludes>
            <exclude>**/foo/**</exclude>
        </excludes>
    </configuration>
</plugin>

【讨论】:

  • 如果你只是想从你的最终 jar 中排除,你不需要“调用”任何东西。 maven-jar-plugin 默认绑定到生命周期。在这里您只需要提供此处演示的配置即可。
  • 这与删除无关。它只是从结果 JAR 中排除。
  • 我认为您要排除的目录下有子目录。检查更新
  • 现在正确答案已经发布了亲爱的。顺便感谢您的宝贵时间。
【解决方案2】:

您可以参考:Maven - exclude folder from build

总之

试试

&lt;exclude&gt;**/foo/**&lt;/exclude&gt;

它将 foo 作为文件夹排除

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-07
    • 2015-12-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多