如何在Maven中为生成的源创建文件夹?

问题描述:

我必须使用wsimport生成源代码,并且我认为它应该转到/ target/generated-sources/wsimport而不是/ src/main/java。如何在Maven中为生成的源创建文件夹?

问题是wsimport需要在执行前创建的目标文件夹,并且失败。我可以使用任何maven插件首先创建该dir。我可以用蚂蚁做,但我更愿意将它保存在POM中。

我必须生成使用wsimport的来源,我认为它应该去/目标/生成来源/ wsimport的,而不是/ src目录/主/ JAVA。

这是一个正确的假设。

问题是wsimport需要执行前创建的目标文件夹,并且失败。我可以使用任何maven插件首先创建该dir。我可以用蚂蚁做,但我更愿意将它保存在POM中。

我从来没有注意到这个问题(并认为它是一个错误,插件必须照顾这样的事情)。

怪异的是,WsImportMojo似乎通过调用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; 
     } 
     ... 
    } 
    ... 
}

你能告诉你如何调用该插件及其配置?

+0

我正在执行使用exec-maven-plugin的wsimport,这是问题所在。我切换到jaxws-maven-plugin,现在它适用于我。 – Eanlr 2010-10-19 13:18:48

+0

也许除了在生成源阶段中处理每个WSDL之后编译源。我无法将-Xnocompile参数传递给wsimport,但无论如何它都可以工作。 – Eanlr 2010-10-19 13:21:52

+0

@Lorean不确定,但是1.你应该能够使用'args'可选参数声明可选的wsimport commnd-line选项2.看起来这个插件默认传递了-Xnocompile。 – 2010-10-19 13:43:41

尝试使用add source目标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> 
+1

这并不回答这个问题(并且不是必需的) – 2010-10-18 11:35:06

+0

但是对那些有类似问题的人有帮助。 – 2016-04-27 09:22:33