Search code examples
javajax-wsjava-ee-6

Error when compiling a basic web service client in Java


I am trying to run the following java EE web service client for days:

package servclient;

import tuto.helloserv.HelloService;
import javax.xml.ws.WebServiceRef;

public class ServClient {

    @WebServiceRef(wsdlLocation = "http://localhost:1991/HelloService/HelloService?wsdl")
    public static HelloService helloServ;

    public static void main(String[] args) {
        System.out.println(webCall("world"));
    }

    private static String webCall(java.lang.String arg0) {
        tuto.helloserv.Hello port = helloServ.getHelloPort();
        return port.webCall(arg0);
    }
}

Yet I get the following error on netbeans even though the web service url is true;

Exception in thread "main" java.lang.NullPointerException
    at servclient.ServClient.webCall(ServClient.java:25)
    at servclient.ServClient.main(ServClient.java:21)
C:\Users\DevShop\Documents\wapps\ServClient\nbproject\build-impl.xml:1329: The following error occurred while executing this line:
C:\Users\DevShop\Documents\wapps\ServClient\nbproject\build-impl.xml:981: Java returned: 1
BUILD FAILED (total time: 1 second)

I run java 1.8.0_261 on my machine and I cant find any clear solution to this in any of the known forums.


Solution

  • The annotation @WebServiceRef is used with java EE not SE

    So in order to use the service from java SE you need to generate the client for the service from the wsdl

    see this tutorial about wsimport : Java Brains wsimport tool And this one too will help : Calling the service from generated client