tags:

views:

12

answers:

1

Hi.

I need to create a subdirectory within the target directory when compiling with maven2. The reason is that I'm using a plugin which grabs responses to SOAP-requests and store them in /target/xml in the integration-test phase.

The problem is that if I specify the plugin's savepath to (in example): ${basedir}/target/xml the plugin throws a FileNotFoundException. The reason I want the file to be in /target is so that the directory is cleaned when invoking mvn clean.

Any suggestions?

+1  A: 

You could create a common abstract base class that your test case classes extend.
Add a static initializer initializer to the abstract base class that checks whether the directory exists and if not then creates it.

The static initializer block will be executed the first time that the base class is loaded, and will be executed before any static initializer blocks or constructors in the test case sub-classes.

EDIT: OK, then you'll have to uglify your pom with the plugin definition below, which will bind to the generate-test-resources phase, and invoke the antrun plugin to create the directory.

  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.4</version>
        <executions>
          <execution>
            <phase>generate-test-resources</phase>
            <configuration>

              <tasks>
                <echo message="Creating test output directory"/>
                <mkdir dir="./target/xml"/>
              </tasks>

            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
  </build>
crowne
I'm using a maven2 plugin to do the testing (soapui) so that won't work in my case I'm afraid (the testcases are specified in a soapui project which the plugin loads and run in the integration-test phase). It would be easiest just to save the xml files in the target directory, but it'll be messy so I'd rather create a subdirectory within target with the name "xml" so that the xml files are saved there.
John
Thank you. It sure is ugly but it does the trick - I guess I could just create the output directory outside of the target directory but then I would have to define the maven clean plugin so that it cleans up the response XMLs, hehe. Accepted.
John