问题
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