maven war 插件将我的资源放在 war 根目录中
maven war plugin put my resources in war root directory
我不明白为什么我把webResources
入口放在maven-war-plugin
里,资源就放在war根目录下。我认为它应该只放在 WEB-INF/classes
中。
这是我的 maven-war-plugin
配置:
<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
但不在根 war 目录中。
这是预期的行为。引用 maven-war-plugin
文档:
The WAR Plugin is also capable of including resources not found in the default resource directory through the webResources parameter.
...
external-resource2.jpg
and image2
are copied to the root of the WAR, preserving the directory structure.
以后:
By default web resources are copied to the root of the WAR
如果要覆盖默认目标路径,可以指定<targetPath>
属性。例如,如果您希望 Web 资源位于 WEB-INF
内,您可以这样配置插件:
<webResources>
<resource>
<excludes>
<exclude>dbre.xml</exclude>
</excludes>
<directory>src/main/resources</directory>
<targetPath>WEB-INF</targetPath>
</resource>
</webResources>
我不明白为什么我把webResources
入口放在maven-war-plugin
里,资源就放在war根目录下。我认为它应该只放在 WEB-INF/classes
中。
这是我的 maven-war-plugin
配置:
<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
但不在根 war 目录中。
这是预期的行为。引用 maven-war-plugin
文档:
The WAR Plugin is also capable of including resources not found in the default resource directory through the webResources parameter.
...
external-resource2.jpg
andimage2
are copied to the root of the WAR, preserving the directory structure.
以后:
By default web resources are copied to the root of the WAR
如果要覆盖默认目标路径,可以指定<targetPath>
属性。例如,如果您希望 Web 资源位于 WEB-INF
内,您可以这样配置插件:
<webResources>
<resource>
<excludes>
<exclude>dbre.xml</exclude>
</excludes>
<directory>src/main/resources</directory>
<targetPath>WEB-INF</targetPath>
</resource>
</webResources>