2010-10-18 79 views
4

我必須使用wsimport生成源代碼,並且我認爲它應該轉到/ target/generated-sources/wsimport而不是/ src/main/java。如何在Maven中爲生成的源創建文件夾?

問題是wsimport需要在執行前創建的目標文件夾,並且失敗。我可以使用任何maven插件首先創建該dir。我可以用螞蟻做,但我更願意將它保存在POM中。

回答

2

我必須生成使用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

3

嘗試使用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