我正在尝试使用maven将两个单独的目录及其文件复制到不同的位置目录中,并且无法实现此目的,是否有任何正文帮助?
** src / com / smepath ----> buildDirectory /安装/ ****
** src / com / someotherpath -----> buildDirectory / XSD / ****
虽然这里有一个相关的问题(Best practices for copying files with Maven)但是没有解决我的问题。
我正在尝试更改以下解决方案,即
<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>${project.build.directory}/install</outputDirectory>
<resources>
<resource>
<directory>src/main/resources/common/install</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources/${env}/install</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
就像我为了说第二个目录位置xsd
创建一个类似的条目,然后第二个覆盖第一个。
在<excution>
或额外<executions>
内使用额外<configuration>
也无效。
答案 0 :(得分:2)
在你的pom中添加第二个<execution>
应该有效
我的猜测是你没有为每个阶段指定一个唯一的<id>
。
我的项目布局如下:
src/main/resources/foo
|_a.txt
|_b.txt
src/main/resources/bar
|_c.txt
src/main/resources/baz
|_d.txt
src/main/resources/fum
|_e.txt
|_f.txt
在clean validate
之后我最终复制了我的文件:
target/location-1
|_a.txt
|_b.txt
|_c.txt
target/location-2
|_d.txt
|_e.txt
|_f.txt
在我的pom.xml中使用以下插件定义
<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>${project.build.directory}/location-1</outputDirectory>
<resources>
<resource>
<directory>src/main/resources/foo</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources/bar</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>${project.build.directory}/location-2</outputDirectory>
<resources>
<resource>
<directory>src/main/resources/baz</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources/fum</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
您应该可以使用上面的示例来复制安装和xsd文件。
答案 1 :(得分:0)
虽然我正在使用@azurefrog建议的额外<execution>
解决方案,但我也能够使用以下解决方案实现此目的。
在这里,我将我的目录install
和xsd
放在resources
目录中并进一步使用这些内容。
<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>${project.build.directory}/resources</outputDirectory>
<resources>
<resource>
<directory>src/main/resources/common</directory>
<includes>
<include>install*/**</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources/${env}</directory>
<includes>
<include>install*/**</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources/common</directory>
<includes>
<include>xsd*/**</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>