2015-11-16 114 views
2

我不明白为什么当我把webResources条目放入maven-war-plugin时,资源被放置在war根目录下。我认为它应该只在WEB-INF/classes。 这是我的maven-war-plugin配置:maven war插件把我的资源放入war根目录

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-war-plugin</artifactId> 
    <version>2.2</version> 
    <!-- <configuration> <webXml>target/web.xml</webXml> </configuration> --> 
    <configuration> 
     <webResources> 
      <resource> 
       <excludes> 
        <exclude>dbre.xml</exclude> 
       </excludes> 
       <directory>src/main/resources</directory> 
      </resource> 
     </webResources> 
     <archive> 
      <manifest> 
       <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries> 
      </manifest> 
     </archive> 
    </configuration> 
</plugin> 

如果我删除<webResources>项,只有在默认src/main/resources文件拷贝到WEB-INF/classes,但不是在根目录下的战争。

回答

4

这是预期的行为。引用maven-war-plugin文档:

的WAR插件还能够包括通过webResources参数默认的资源目录未找到资源。
...
external-resource2.jpgimage2被复制到WAR的根目录,保留目录结构。

及更高版本:

默认情况下,网络资源被复制到WAR的根

如果要覆盖默认的目标路径,您可以指定<targetPath>属性。例如,如果您希望网络资源位于WEB-INF之内,您可以像这样配置插件:

<webResources> 
    <resource> 
    <excludes> 
     <exclude>dbre.xml</exclude> 
    </excludes> 
    <directory>src/main/resources</directory> 
    <targetPath>WEB-INF</targetPath> 
    </resource> 
</webResources>