How to create folder for generated sources in Maven?
Asked Answered
C

2

5

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.

Cunning answered 18/10, 2010 at 11:0 Comment(0)
M
2

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

This is a correct assumption.

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.

I never noticed this problem (and would consider it as a bug, a plugin has to take care of such things).

The weird part is that WsImportMojo seems to do what is has to 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 invoke the plugin and its configuration?

Marta answered 18/10, 2010 at 12:2 Comment(3)
I was executing wsimport using exec-maven-plugin and this was the problem. I switched to jaxws-maven-plugin and now it works fine for me.Cunning
Maybe except compiling sources after processing each WSDL in generate-sources phase. I can't pass -Xnocompile argument to wsimport but it works anyway.Cunning
@Lorean Not sure but 1. you should be able to declare optional wsimport commnd-line options using the args optional parameter 2. it seems the plugin is passing -Xnocompile by default.Marta
I
5

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>  
Intermolecular answered 18/10, 2010 at 11:18 Comment(2)
This doesn't answer the question (and is not necessary)Marta
But is helpful for those who have similar problems.Extinct
M
2

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

This is a correct assumption.

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.

I never noticed this problem (and would consider it as a bug, a plugin has to take care of such things).

The weird part is that WsImportMojo seems to do what is has to 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 invoke the plugin and its configuration?

Marta answered 18/10, 2010 at 12:2 Comment(3)
I was executing wsimport using exec-maven-plugin and this was the problem. I switched to jaxws-maven-plugin and now it works fine for me.Cunning
Maybe except compiling sources after processing each WSDL in generate-sources phase. I can't pass -Xnocompile argument to wsimport but it works anyway.Cunning
@Lorean Not sure but 1. you should be able to declare optional wsimport commnd-line options using the args optional parameter 2. it seems the plugin is passing -Xnocompile by default.Marta

© 2022 - 2024 — McMap. All rights reserved.