39

I have a maven project which uses wsgen to generate XSD files from the compiled java classes.

The problem is that I want to add the generated files to the jar as resources. But since the resource phase runs before the process-classes phase, I can't add them.

Is there a way to tell maven to add additional resources that were generated at the process-classes phase?

bruno
  • 2,213
  • 1
  • 19
  • 31
Avner Levy
  • 6,601
  • 9
  • 53
  • 92

1 Answers1

54

I would suggest to define the output directory for the XSD files into target/classes (may be with a supplemental sub folder which will be packaged later during the package phase into the jar. This can be achieved by using the maven-resources-plugin.

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.0.2</version>
        <executions>
          <execution>
            <id>copy-resources</id>
            <phase>process-classes</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.outputDirectory}</outputDirectory>
              <resources>          
                <resource>
                  <directory>${basedir}/target/xsd-out</directory>
                  <filtering>false</filtering>
                </resource>
              </resources>              
            </configuration>            
          </execution>
        </executions>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>

You need to take care that the resources plugin is positioned after the plugin which is used to call the wsgen part. You can also use the prepare-package phase instead to make sure the resources will be correctly packaged.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • and how to specify the package to scan ? not all the packages – Hayi Jul 06 '14 at 04:21
  • 1
    This only worked after I moved `configuration` from `execution` to `plugin`. Maven xsd allows both, but this plugin seems not to – Tim Büthe Jul 21 '17 at 15:55
  • The configuration handling for has never been other than that both working. using configuration in execution limited the configuration to the execution and using the configuration at plugin level defines configuration for all executions...If it works at your side not there is something other different/wrong... – khmarbaise Jul 22 '17 at 09:15
  • But in my case , maven-jar-plugin is getting invoked before maven-resources-plugin – SUMIT Sep 28 '22 at 18:38
  • Running maven-jar-plugin before maven-resources-plugin does not make sense... there is something wrong in your project... violating the basic life cycle ideas. – khmarbaise Sep 28 '22 at 19:36