How to create folder for generated sources in Maven?

Eanlr picture Eanlr · Oct 18, 2010 · Viewed 10.4k times · Source

I have to generate sources using wsimport and i assume that it should go to /target/generated-sources/wsimport rather than /src/main/java.

The problem is that wsimport needs target folder created before execution and it fails. Can I create that dir first using any maven plugin. I can do it using ant but i prefer to keep it in POM.

Answer

serg10 picture serg10 · Oct 18, 2010

Try using the add source goal of the build helper plugin:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <executions>
    <execution>
      <id>add-source</id>
      <phase>generate-sources</phase>
      <goals>
        <goal>add-source</goal>
      </goals>
      <configuration>
        <sources>
          <source>${basedir}/target/generated/src/wsimport</source>
        </sources>
      </configuration>
    </execution>
  </executions>
</plugin>