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

时间:2015-02-04 09:16:34

标签: maven

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指定为附加资源目录,并将其复制到root war目录中。但我不想要生产版本中提供的所有开发文件。

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

1 个答案:

答案 0 :(得分:2)

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