【问题标题】:Maven webapp with non-default web resource directory具有非默认 Web 资源目录的 Maven webapp
【发布时间】:2015-02-04 18:22:22
【问题描述】:

Maven 根据http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html 将默认 webapp 目录设置为src/main/webapp

我们使用 IDE 配置的服务器进行开发,该服务器使用此目录中的文件进行服务。服务器不能从另一个目录工作,而是直接从文件系统提供服务。这样做的好处是我们对源文件所做的每一次更改都可以立即看到。

但是,webapp 目录中的所有文件都没有被缩小,没有连接等。我目前已经设置 grunt 从 webapp 目录中获取文件并将部署就绪的资源放在src/main/webapp/dist

问题:在构建战争时,src/main/webapp 的内容被复制到战争中,但我希望将来自src/main/webapp/dist 的部署就绪文件复制到战争中。

我已经尝试了无数次谷歌搜索来搜索这个主题,但我觉得自己很愚蠢。如前所述,我找到了“http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html”,上面写着“这些设置可以通过项目描述符覆盖”,但它没有显示如何。我发现 http://maven.apache.org/pom.html#Build_Element 没有显示 webapp 目录。我再次找到“http://maven.apache.org/guides/mini/guide-using-one-source-directory.html”,它没有指定如何更改目录。

我知道我可以将src/main/webapp/dist 指定为附加资源目录,它将被复制到根war 目录中。但我不希望生产版本中的所有开发文件都可用。

另外,如果有人知道处理我的一般方法的更好方法,我也想听听。

【问题讨论】:

    标签: maven


    【解决方案1】:

    我终于找到了设置。 http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html

    添加

    <warSourceDirectory>src/main/webapp/dist</warSourceDirectory>
    

    到 maven-war-plugin 配置,像这样:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <warSourceDirectory>src/main/webapp/dist</warSourceDirectory>
        </configuration>
    </plugin>
    

    【讨论】:

      猜你喜欢
      • 2018-08-24
      • 2018-09-13
      • 2011-07-31
      • 2017-12-01
      • 2010-09-18
      • 1970-01-01
      • 1970-01-01
      • 2018-02-18
      • 2012-04-05
      相关资源
      最近更新 更多