Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven: How to add resources which are generated after compilation phase

Tags:

java

maven

jax-ws

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?

like image 451
Avner Levy Avatar asked Jun 07 '12 16:06

Avner Levy


People also ask

What does Mvn generate sources do?

The “maven-source” plugin is used to pack your source code and deploy along with your project. This is extremely useful, for developers who use your deployed project and also want to attach your source code for debugging.

Where do you put resources in POM?

Via the resources area in the pom you can filter files from their way src/main/resources to the target/classes folder. The lifecycle of Maven is not influenced by this. I have added resources successfully in . Jar file.


1 Answers

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.

like image 185
khmarbaise Avatar answered Sep 25 '22 12:09

khmarbaise