名称冲突在Wsimport生成的类和我原始的Web服务类 [英] Name Collision In Wsimport Generated Class And My Original Web Service Class

查看:489
本文介绍了名称冲突在Wsimport生成的类和我原始的Web服务类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Web服务类定义如下:

I have a simple web service class defined as follows:

package com.me.basiccalcws;

import javax.jws.WebService;

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

我使用 wsgen 工具生成 wsdl

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

然后我使用 wsimport 生成客户端存根:

Then I use wsimport to generate client stubs:

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

运行 wsimport 后生成的文件如下:

The files that are generated after running wsimport are as follows:

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

,所有这些文件与我的命名空间相同原始Web服务类(com.me.basiccalcws)。

and all these files have the same namespace as my original web service class (com.me.basiccalcws).

当我将这些文件导入我的Eclipse项目时,存在名称冲突。我的原始类名是Calculator,而且 wsimport 工具在同一个命名空间中创建了另一个名为Calculator的类。

When I import these files into my Eclipse project there is a name collision. My original class name was Calculator and yet the wsimport tool created another class called Calculator in the same namespace.

如何防止此命名空间/名称冲突(或是有意的)?

How do I prevent this namespace/name collision (or is it intentional)?

推荐答案

最简单的方法是提供 targetNamespace
$

The easiest thing you can do is provide the targetNamespace in the javax.jws.WebService annotation, something like that.

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;
    }
}

如果您不提供 -p 选项,位于 wsimport ,此 targetNamespace 是命运包。

If you dont provide the -p option in the wsimport, this targetNamespace is the destiny package.

这篇关于名称冲突在Wsimport生成的类和我原始的Web服务类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆