1

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/*</argument>
            <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

Dave
  • 8,667
  • 25
  • 72
  • 90
  • The first questions comes to my mind: Why do you need that? In which relationship do you need this? (Looks like a webapp?; exploded using of a webapp?); You are violating the rule not to change/modify the src folder by any build... – khmarbaise Aug 05 '11 at 17:51
  • 1
    Ever tried deploying a Mavenized Grails app to an embedded Jetty server and configuring a second context path? Now you're like, "What the hell are you talking about?" That's why I asked the simpler question above. – Dave Aug 08 '11 at 15:12
  • I assume that you need the second context for Unit/Integrationg testing? Yes than you the maven-jetty-plugin into different life-cycle-phases with different configurations). – khmarbaise Aug 08 '11 at 15:32

3 Answers3

2

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.

kiltek
  • 3,183
  • 6
  • 47
  • 70
Anup
  • 600
  • 3
  • 9
1

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>
orien
  • 2,130
  • 16
  • 20
0
  1. mvn -X might be more revealing

  2. Many people would use the maven-antrun-plugin and script this in ant so as to get a portable solution.

bmargulies
  • 97,814
  • 39
  • 186
  • 310