当我用maven创建war包时,目录“src / main / resources”下的文件和目录被复制到/ WEB-INF / classes而不是/ WEB-INF中。如何将它们复制到/ WEB-INF?
感谢, 兰特
更新: 在我的pom中,我现在用它:
<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>
我用:
启动mvnmvn -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,该代码段基本上与文档相同 任何想法?
答案 0 :(得分:28)
配置outputDirectory
插件的resources:resources
参数,或将您的文件放在src/main/webapp/WEB-INF/
目录下。
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]中阶段上挂钩的所有插件目标,因此不需要显式调用它们。
答案 1 :(得分:25)
Web资源与java资源不同,后者应放在类路径中。 Web资源通过war插件处理,应放在src\main\webapp\WEB-INF\
中。在这种情况下,它将自动工作,而无需在pom.xml中进行任何其他配置
答案 2 :(得分:0)
此配置正在添加插件pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<webResources>
<!--copy resource file location-->
<resource>
<directory>${project.build.directory}/classes</directory>
</resource>
</webResources>
<!--location for add file-->
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
</configuration>
</plugin>