开发者

How to create a subdirectory within target with Maven2

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 p开发者_StackOverflowlugin'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?


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜