Name Collision In Wsimport Generated Class And My Original Web Service Class

泄露秘密 提交于 2020-01-06 07:59:31

问题


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

I use the wsgen tool to generate a wsdl:

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

Then I use wsimport to generate client stubs:

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

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

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).

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)?


回答1:


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

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



来源:https://stackoverflow.com/questions/14405176/name-collision-in-wsimport-generated-class-and-my-original-web-service-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!