Maven: copying directories using exec plugin
I'm using Maven 3.0.3. I'm having trouble using the Maven exec plugin to copy the contents of one directory to another. Sadly, when I include this plugin in my pom.xml …
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<configuration>
<executable>cp</executable>
<arguments>
<argument>-r</argument>
<argument>web-app/*</argu开发者_运维百科ment>
<argument>src/main/webapp</argument>
</arguments>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
</plugin>
It isn't working. I get the error below …
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.1.1:exec (default-cli) on project jx: Result of /bin/sh -c cd /Users/davea/Documents/workspace/mycoUSA2/Technology/nna/myco2usa/jx && cp -r 'web-app/*' src/main/webapp execution is: '1'. -> [Help 1]
Does anyone know how I can modify my plugin config to copy the contents of one directory to another? Thanks, - Dave
If you are using bash, try the following:
<executable>bash</executable>
<arguments>
<argument>-c</argument>
<argument>cp -r web-app/* src/main/webapp</argument>
</arguments>
This spawns a new bash and gives it the command cp -r web-app/* src/main/webapp
to execute.
You can also test if it works for you by inputting this into a normal Terminal window first:
bash -c "cp -r web-app/* src/main/webapp"
Note that the "
signs do make a difference as the exec-maven-plugin
does insert them automatically, thus they are not included in the <argument>
-tag.
Note the command it ran. From the error output:
cp -r 'web-app/*' src/main/webapp
Note in particular the 'web-app/*'
file it has tried to copy. Because it has quoted this argument the cp
command is looking for a specific file with the name *
in the web-app directory. Because you don't have a file with this name it has exited with the error code 1
.
The maven-resources-plugin has a goal designed to perform this task. Why not give it a try? It would have the added benefit of making your build platform independent.
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/src/main/web-app</outputDirectory>
<resources>
<resource>
<directory>web-app</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
mvn -X might be more revealing
Many people would use the maven-antrun-plugin and script this in ant so as to get a portable solution.
精彩评论