Wrapper class package.jaxws.methodName is not found. Have you run APT to generate them?解决方案

使用JAX-WS 2.X基于Web容器发布WebService报错,错误信息类似于:

Wrapper class package.jaxws.methodName is not found. Have you run APT to generate them?

用于发布Web服务的接口(SEI)定义如下:

package com.csdn.jaxws.recipe01;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
import javax.jws.soap.SOAPBinding.Use;

@WebService
@SOAPBinding(style = Style.DOCUMENT, use=Use.LITERAL)
public interface HelloWorld {
    @WebMethod
    String sayHello(String text);
}

实现类:

package com.csdn.jaxws.recipe01;

import javax.jws.WebService;

@WebService(endpointInterface = "com.csdn.jaxws.recipe01.HelloWorld")
public class HelloWorldImpl implements HelloWorld {

    @Override
    public String sayHello(String name) {
        return "hello," + name;
    }

}

正如错误信息中所提示的没有使用工具生成对应的工具类,解决方法如下:
我们需要用到jdk自带的wsgen工具,打开Window控制台,进入工程的bin目录下的classes目录,输入:

wsgen -keep -cp . com.csdn.jaxws.recipe01.HelloWorldImpl

將生成工具类拷贝到com.csdn.jaxws.recipe01.jaxws包下即可:

我的工程结构如下图所示:

其中SayHello.java和SayHelloResponse.java为wsgen工具所生成。

你可能感兴趣的:(Web,service)