Maven:如何使用在WEB-INF中复制的资源获取战争包? [英] Maven: how to get a war package with resources copied in WEB-INF?
问题描述
当我使用Maven创建一个战争软件包时,目录"src/main/resources"下的文件和目录将复制到/WEB-INF/classes中而不是/WEB-INF中.如何将它们复制到/WEB-INF?
when I create a war package with maven, files and directories under the directory "src/main/resources" are copied in /WEB-INF/classes instead of /WEB-INF. How can I get them copied in /WEB-INF?
谢谢, 兰特
更新: 现在在我的pom中使用这个:
UPDATE: in my pom now I use this:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>war</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>myapp/target/WEB-INF</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
然后我用以下命令启动mvn:
and I launch mvn with:
mvn -Dmaven.test.skip = true干净的程序包资源:复制资源
mvn -Dmaven.test.skip=true clean package resources:copy-resources
但是我得到了
[INFO] One or more required plugin parameters are invalid/missing for 'resources:copy-resources'
[0] Inside the definition for plugin 'maven-resources-plugin' specify the following:
<configuration>
...
<outputDirectory>VALUE</outputDirectory>
</configuration>.
[1] Inside the definition for plugin 'maven-resources-plugin' specify the following:
<configuration>
...
<resources>VALUE</resources>
</configuration>.
我正在使用maven 2.2,并且代码段基本上与文档相同 有什么主意吗?
I'm using maven 2.2 and the snippet basically is the same of the documentation any idea?
推荐答案
要么配置resources:resources
插件的outputDirectory
参数,要么将文件放在src/main/webapp/WEB-INF/
目录下.
资源插件
either configure the outputDirectory
parameter of resources:resources
plugin, or put your files under src/main/webapp/WEB-INF/
directory.
resource plugin
此配置对我有用:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.2</version>
<executions>
<execution>
<id>default-copy-resources</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<overwrite>true</overwrite>
<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
您可以运行somePhase
形式或目标somePlugin:someGoal
形式的阶段.阶段调用将按间隔[validate,phase]的顺序调用挂在阶段上的所有插件目标,因此无需显式调用它们.
you can run a phase in the form somePhase
or a goal somePlugin:someGoal
. The phase invocations will invoke all plugins goals hooked on phases in interval [validate,phase] in order, so there's no need to explicitly call them.
这篇关于Maven:如何使用在WEB-INF中复制的资源获取战争包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!