agenthost
agenthost

Reputation: 768

How to correctly specify the wsdl location in JAX-WS?

I received a code recently for a JAX-WS client application, where I saw that a wsdl was specified locally in order to build the endpoint. But it was specified statically, and I do not think this is right.

static {
    URL url = null;
   try {
      url = new URL("file:/home/user/work/src/proj/myproject.wsdl");
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    WSDL_LOCATION = url;
}

This is not the correct way to do it is it? What is another way to specify the location of this wsdl?

Upvotes: 1

Views: 2760

Answers (2)

Garry
Garry

Reputation: 4533

You can place the wsdl in your classpath and refer to it as below:

URL url = ClassLoader.getResource("myproject.wsdl");

Or

URL url = ClassLoader.getSystemResource("myproject.wsdl");

Upvotes: 3

Tunaki
Tunaki

Reputation: 137084

There are two possible ways:

  • Add the WSDL as a resource of your project. It will then be embedded inside the final jar and you can access it with Class.getResource(String name).
  • Point to the WSDL hosted by the web server. It will typically be of the form http://example.com/MyWebService?WSDL (note the ?WSDL at the end).

Upvotes: 2

Related Questions