1
我無法讓AutoNameResolution在maven-jaxb2-plugin中工作。 下面是我的POM文件maven-jaxb2-plugin中的AutoNameResolution
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.2</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<args>
<arg>-XautoNameResolution</arg>
</args>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>com.commp.soap.service</generatePackage>
<schemas>
<schema>
<url>https://urltowsdl</url>
</schema>
</schemas>
</configuration>
</plugin>
我無法弄清楚我要去的地方錯了。所有我得到的錯誤是"A class/interface with the same name is already in use. Use a class customization to resolve this conflict."
因爲我正在使用第三方wsdl,大多數功能我不會消耗我只是想要一個簡單的自動解決方案,而不是寫我沒有使用的東西的綁定。
我也嘗試過使用apache cxf。
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>stock-quote-service</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.basedir}/src/main/generated_java</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${project.basedir}/src/main/resources/wsdl/consume.wsdl</wsdl>
<wsdlLocation>http://usrltoWsdl</wsdlLocation>
<serviceName>Consumer</serviceName>
<extraargs>
<extraarg>-verbose</extraarg>
<extraarg>-p</extraarg>
<extraarg>com.projects.webservicex.service</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-xjc-ts</artifactId>
<version>2.2.9</version>
</dependency>
</dependencies>
</plugin>
我跑這既<extraarg>-autoNameResolution</extraarg>
和
<defaultOptions>
<autoNameResolution>true</autoNameResolution>
</defaultOptions>
還是同樣的問題"Two declarations cause a collision in the ObjectFactory class."
如何我只是得到autoNameResolve工作?
編輯 我在調試中看到如下所示的日誌。
[DEBUG] Resolving publicId [http://url/webservices/es/common], systemId [null].
resolvePublic(http://url/webservices/es/common,null)
[DEBUG] Parent resolver has resolved publicId [http://url/webservices/es/common], systemId [null] to [null].
[DEBUG] Resolving publicId [http://url/webservices/es/constants], systemId [null].
resolvePublic(http://url/webservices/es/constants,null)
這其實工作!爲什麼?我確定我的軟件包命名與生成文件中的軟件包名稱不同。但更重要的是,刪除包名後,我甚至不需要autoNameResolution。 – Manoj
您不需要autoNameResolution選項,因爲在同一個名稱空間中沒有相同類的兩個定義,所以只有當您嘗試更改目標包名稱時纔會出現此錯誤。然而,這與這些maven插件無關,而是直接與「jaxb和xjc」相關。 – Macondo