Maven:如何使用WEB-INF中复制的资源获取war包?

Ran*_*ize 23 war maven

当我用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>
Run Code Online (Sandbox Code Playgroud)

我用以下命令启动mvn:

mvn -Dmaven.test.skip =真正的干净包资源: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>.
Run Code Online (Sandbox Code Playgroud)

我正在使用maven 2.2和片段基本上是相同的文档任何想法?

cou*_*ech 29

要么配置插件的outputDirectory参数resources:resources,要么将文件放在src/main/webapp/WEB-INF/目录下. 资源插件

编辑:

这个配置对我有用:

  <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>
Run Code Online (Sandbox Code Playgroud)

你可以在表格somePhase或目标中运行一个阶段somePlugin:someGoal.阶段调用将按顺序调用间隔[validate,phase]中阶段上挂钩的所有插件目标,因此不需要显式调用它们.


kan*_*kan 27

Web资源与java资源不同,后者应放在类路径中.Web资源通过war插件处理,应放入src\main\webapp\WEB-INF\.在这种情况下,它将自动工作,而无需在pom.xml中进行任何其他配置