【问题标题】:Maven: exclude resource from warMaven:从战争中排除资源
【发布时间】:2017-02-25 12:26:57
【问题描述】:

我目前正试图从我建造的战争中排除一些资源。 我已经阅读了文档和论坛,并找到了很多信息。

不幸的是,在我的情况下没有任何效果......

我有一个 Eclipse Maven 项目,如果我是对的,maven-war-plugin 是默认的“战争构建器”,所以我必须在我的 pom.xml 中覆盖它,以便从 buildt 战争中排除资源。

我试过warSourceExcludespackagingExcludeswebResources/excludes

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>${maven.war.version}</version>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <warSourceExcludes>src/main/webapp/frontEndWorkspace</warSourceExcludes>
        <packagingExcludes>src/main/webapp/frontEndWorkspace
        </packagingExcludes>
        <webResources>
            <resource>
                <!-- this is relative to the pom.xml directory -->
                <directory>src/main/webapp</directory>
                <!-- the list has a default value of ** -->
                <excludes>
                    <exclude>**/frontEndWorkspace</exclude>
                </excludes>
            </resource>
        </webResources>
    </configuration>
</plugin>

尽管有这样的配置,我的 Tomcat 中仍然有 frontEndWorkspace 目录推送...

不知道是不是因为我在 Eclipse 环境中使用了它?

提前致谢!

【问题讨论】:

  • 您是否尝试过在没有任何 IDE 的情况下在纯命令行上运行...
  • 否 我确实使用了我的 IDE。为什么?在eclipse中使用maven有问题吗?默认构建的行为不一样?

标签: eclipse maven maven-war-plugin


【解决方案1】:

您可以使用的参数是packagingExcludes,它更通用(适用于完整的战争结构)或warSourceExcludes,如果您要排除的文件专门位于参数warSourceDirectory定义的文件夹中(默认是${basedir}/src/main/webapp)(see here)。当您知道它开始考虑战争的文件夹结构时,它很容易工作。

例子:

这将排除由参数warSourceDirectory(默认为${basedir}/src/main/webapp)定义的文件夹的WEB-INF文件夹中包含的所有*.jsp完成的文件:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <warSourceExcludes>WEB-INF/**/*.jsp</warSourceExcludes>
    </configuration>
</plugin>

这将排除战争中包含的所有文件夹pouet中包含的所有文件(但不包括文件夹结构):

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <packagingExcludes>**/pouet/**/*.*</packagingExcludes>
    </configuration>
</plugin>

你的配置&lt;warSourceExcludes&gt;src/main/webapp/frontEndWorkspace&lt;/warSourceExcludes&gt;的问题是你从源文件夹开始是错误的。您只需删除src/main/webapp 并在frontEndWorkspace 之后添加/** 即可使&lt;warSourceExcludes&gt;/frontEndWorkspace/**&lt;/warSourceExcludes&gt; 正常工作(或&lt;warSourceExcludes&gt;frontEndWorkspace/**&lt;/warSourceExcludes&gt;)。

【讨论】:

  • 感谢您的贡献,但是还是不行,如上所述我使用的是eclipse IDE,所以不知道是不是我的问题的原因...
  • 你的目标是什么? 'mvn clean package' ?
  • 哪个版本的插件和 maven 本身?我在我这边的 eclipse 上测试了这个插件配置,它正在工作,所以我想 eclipse 没有理由参与这个问题
  • 好的,我正在使用 m2e 1.5.1 的 eclipse luna。如上所述我没有指定任何目标,我只是将我的 webapp 拖放到我的服务器上,我知道这是在后面运行 mvn clean package,但我可能错了......
  • 当你从 eclipse 拖放到你的项目部署到你的服务器时,是部署的生成的战争还是文件夹?这有很大的不同,因为在生成战争时,maven-war-plugin 在创建战争时执行排除,因此这意味着使用的临时文件夹包含所有资源(包括排除)。
【解决方案2】:

我在使用 Maven 3 的 Intellij IDEA 中发现了同样的问题。
它生成的war文件包含我要排除的目录。
UPD 解决方案是使用如下语法来消除 myFolder 目录

<webResources>
    <resource>
      <!-- this is relative to the pom.xml directory -->
      <directory>src/main/resources</directory>
         <excludes>
           <exclude>**/myFolder/**</exclude>
         </excludes>
    </resource>

</webResources>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-05
    • 1970-01-01
    • 2010-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多