使用maven将多个资源目录复制到独立目标目录 [英] Copying multiple resource directories to independent target directories with maven

查看:255
本文介绍了使用maven将多个资源目录复制到独立目标目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Maven资源插件

此目标要求您配置要复制的资源,并指定outputDirectory。

This goal requires that you configure the resources to be copied, and specify the outputDirectory.

复制使用maven将 basedir 中的两个(或更多)外部资源目录添加到构建输出目录中(参见 blah uggh )。

Copy two (or more) external resource directories within the basedir to the build output directory using maven (see blah and uggh).

${basedir}/ 
  - pom.xml
  - blah/
  - uggh/
  - src/
    - main/..
    - test/..
  - target/
    - classes/..
    - blah/
    - uggh/

例如,给定上面的目录结构使用maven将 blah uggh 复制到目标目录。复制一个或另一个很容易,但插件只接受一个outputDirectory。如果指定目标目录和两个目录作为资源,则每个目录的内容将复制到 target 但不会目录本身。

For example, given the directory structure above copy blah and uggh to the target directory using maven. It is easy to copy one or the other, however, the plugin only accepts a single outputDirectory. If you specify the target directory and both directories as resources, then the contents of each directory gets copied to target but not the directories themselves.

插件的额外使用会覆盖初始。另外,我已经尝试指定整个 basedir 并且只包含所需的目录。这不会复制任何内容。

Additional use of the plugin overwrites the initial. Also, I've tried specifying the entire basedir and only including the desired directories. This does not copy anything.

以下是复制单个目录的示例:

Here is an example of copying a single directory:

  <plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.6</version>
    <executions>
      <execution>
        <id>copy-resources</id>
        <phase>validate</phase>
        <goals>
          <goal>copy-resources</goal>
        </goals>
        <configuration>
          <outputDirectory>${basedir}/target/blah</outputDirectory>
          <resources>
            <resource>
                <directory>blah</directory>
                <filtering>true</filtering>
            </resource>
          </resources>
        </configuration>
      </execution>
    </executions>
  </plugin>


推荐答案

这是文件的最终位置:

<outputDirectory>${basedir}/target/blah</outputDirectory>

这是从以下地方复制的地方:

This is where it is copied from:

<directory>src/main/otherresources</directory>

会有< include> < includes> 标记以告知文件名

There would be an <include> or <includes> tag to tell the file name(s)

倍数

您需要多个< execution> ,其中包含不同的< id> s:

You need multiple <execution>s with different <id>s for multiple folders:

  <plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.6</version>
    <executions>
      <execution>
        <id>copy-resources-1</id>
        <phase>validate</phase>
        <goals>
          <goal>copy-resources</goal>
        </goals>
        <configuration>
          <outputDirectory>${basedir}/target/blah</outputDirectory>
          <resources>
            <resource>
                <directory>blah</directory>
                <filtering>true</filtering>
            </resource>
          </resources>
        </configuration>
      </execution>
      <execution>
        <id>copy-resources-2</id>
        <phase>validate</phase>
        <goals>
          <goal>copy-resources</goal>
        </goals>
        <configuration>
          <outputDirectory>${basedir}/target/ughh</outputDirectory>
          <resources>
            <resource>
                <directory>ughh</directory>
                <filtering>true</filtering>
            </resource>
          </resources>
        </configuration>
      </execution>
    </executions>
  </plugin>

这篇关于使用maven将多个资源目录复制到独立目标目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆