0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

wsimportのエラー対応(クラス/インタフェースがすでに使用されています/A class/interface with the same name "xxx" is already in use)

Last updated at Posted at 2020-10-09

Java用のSoapクライアントコードの自動生成に利用するwsimportで発生したエラーメッセージが日本語になっていて、日本語情報だと見つからず、ちょっと遠回りしたので備考。

エラーメッセージ

日本語だと

[ERROR] 同じ名前"xxxxxx.SampleResponse"のクラス/インタフェースがすでに使用されています。
この競合を解決するには、クラス・カスタマイズを使用してください。

英語だと

[ERROR] A class/interface with the same name "xxx" is already in use. 
Use a class customization to resolve this conflict.

原因と対策

原因は2つ考えられる。

  • -pオプションを指定してパッケージ名を任意に指定したことにより名称が重複
  • wsdl内でname属性の値が重複している・・・サーバ側が.NET(拡張子asmx)だと発生するのかも

前者の場合は-pオプションを指定せず(=つまりwsdlにしたがって)にwsimportを実行すれば解決。

自分の場合は後者だった。具体的には以下のSampleResponseのように同じname()を持つ定義があるのが悪い模様。
片方の定義を削除すると重複エラーは消えるが、メソッドから参照されているので結局エラーになる。

hoge.wsdl
<s:element name="SampleResponse">
  <s:complexType>
    <s:sequence>
      <s:element minOccurs="1" maxOccurs="1" name="Response" nillable="true" type="tns:SampleResponse" />
    </s:sequence>
  </s:complexType>
</s:element>
<s:complexType name="SampleResponse">
  <s:sequence>
    <s:element minOccurs="0" maxOccurs="1" name="Result" type="tns:SampleResponseResult" />
    <s:element minOccurs="0" maxOccurs="1" name="ApplicationResponse" type="tns:SampleResponseApplicationResponse" />
  </s:sequence>
</s:complexType>

この場合の対策は、wsimportコマンドに以下のオプションを指定すること。-Bの後には空白ないので注意。

-B-XautoNameResolution

なお、この場合は、SampleResponseSampleResponse2というクラスが生成されるので適宜修正する。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?