How to create a folder for generated sources in Maven?

I need to generate sources using wsimport, and I assume that it should go to / target / generated -sources / wsimport, and not / src / main / java.

The problem is that wsimport needs a destination folder created before it executes, and it does not work. Can I create this directory first using any maven plugin. I can do this with ant, but I prefer to store it in POM.

+4
source share
2 answers

I need to generate sources using wsimport, and I assume that it should go to / target / generated -sources / wsimport, and not / src / main / java.

This is a correct guess.

The problem is that wsimport needs a destination folder created before it executes, and it does not work. Can I create this directory first using any maven plugin. I can do this with ant, but I prefer to store it in POM.

I never noticed this problem (and would consider it as an error, the plugin should take care of such things).

The strange part is that WsImportMojo seems to do what it needs by calling File#mkdirs() :

 public void execute() throws MojoExecutionException { // Need to build a URLClassloader since Maven removed it form the chain ClassLoader parent = this.getClass().getClassLoader(); String originalSystemClasspath = this.initClassLoader( parent ); try { sourceDestDir.mkdirs(); getDestDir().mkdirs(); File[] wsdls = getWSDLFiles(); if(wsdls.length == 0 && (wsdlUrls == null || wsdlUrls.size() ==0)){ getLog().info( "No WSDLs are found to process, Specify atleast one of the following parameters: wsdlFiles, wsdlDirectory or wsdlUrls."); return; } ... } ... } 

Could you show how you call the plugin and its configuration?

+2
source

Try using the add source goal to embed the 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> 
+3
source

Source: https://habr.com/ru/post/984292/


All Articles