具有非默认 Web 资源目录的 Maven webapp

Maven webapp with non-default web resource directory

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

问题:建war的时候,src/main/webapp的内容被复制到war,但是我想要只有src/main/webapp/dist 中的部署就绪文件将被复制到 war。

我已经尝试了无数次 google 搜索该主题,但我觉得自己很愚蠢。如前所述,我找到了“http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html”,它说的是 "these settings can be overridden via the project descriptor",但它没有显示如何。我发现 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 目录中。但我不希望生产版本中的所有开发文件都可用。

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

我终于找到了设置。 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>