简体   繁体   English

Wsimport生成的类和我的原始Web Service类中的名称冲突

[英]Name Collision In Wsimport Generated Class And My Original Web Service Class

I have a simple web service class defined as follows: 我有一个简单的Web服务类,定义如下:

package com.me.basiccalcws;

import javax.jws.WebService;

@WebService
public class Calculator {
    public int add(int a, int b) {
        return a + b;
    }
}

I use the wsgen tool to generate a wsdl : 我使用wsgen工具生成一个wsdl

wsgen -classpath ..\bin -wsdl -s src -r wsdl -d bin com.me.basiccalcws.Calculator

Then I use wsimport to generate client stubs: 然后,我使用wsimport生成客户端存根:

wsimport -s src ..\_wsgen\wsdl\CalculatorService.wsdl

The files that are generated after running wsimport are as follows: 运行wsimport后生成的文件如下:

Add.java
AddResponse.java
Calculator.java
CalculatorService.java
ObjectFactory.java
package-info.java

and all these files have the same namespace as my original web service class (com.me.basiccalcws). 所有这些文件都具有与原始Web服务类(com.me.basiccalcws)相同的名称空间。

When I import these files into my Eclipse project there is a name collision. 当我将这些文件导入Eclipse项目时,会发生名称冲突。 My original class name was Calculator and yet the wsimport tool created another class called Calculator in the same namespace. 我最初的类名称是Calculator,但是wsimport工具在同一名称空间中创建了另一个名为Calculator的类。

How do I prevent this namespace/name collision (or is it intentional)? 如何防止此名称空间/名称冲突(或故意)?

The easiest thing you can do is provide the targetNamespace in the javax.jws.WebService annotation, something like that. 您可以做的最简单的事情就是在javax.jws.WebService批注中提供targetNamespace

package com.me.basiccalcws;

import javax.jws.WebService;

@WebService(targetNamespace = "http://client.basiccalcws.me.com/")
public class Calculator {
    public int add(int a, int b) {
        return a + b;
    }
}

If you dont provide the -p option in the wsimport , this targetNamespace is the destiny package. 如果wsimport提供-p选项,则此targetNamespace是目的地软件包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM