2

I have a web service client which works perfectly fine, within which there is a line that defines the location of the WSDL:

@WebServiceClient(name = "CReceiveMOMessageService", 
                  targetNamespace = "http://...", 
                  wsdlLocation = "CReceiveMOMessageService.wsdl")

The code piece should be exported as a runnable JAR and is intended to work on a remote location.

When I define the location of the WSDL as above, it looks for a WSDL file at the directory in which I run the JAR file. Instead what I would like to do is to add the WSDL file to the project folder and export as JAR after that, and configure wsdlLocation parameter in a way that it points to the WSDL within the JAR file.

How can this be achieved?

Bogdan
  • 23,890
  • 3
  • 69
  • 61
Pumpkin
  • 1,993
  • 3
  • 26
  • 32

1 Answers1

3

It is possible to add the WSDL to the JAR. It seems that the convention is to place the WSDL in the JAR at the META-INF/wsdl location (although Oracle tools seem to favor META-INF/wsdls (see point 9 of this Oracle tutorial for example).

I haven't used the Oracle Enterprise Pack for Eclipse and I guess the OEPE ClientGen task does the correct generation of the client classes when you specify to package the WSDL inside the JAR but I don't think it's the same as passing a -wsdllocation META-INF/wsdls/YourService.wsdl parameter when running wsimport.exe:

wsimport.exe will output @WebServiceClient(... wsdlLocation = "META-INF/wsdls/YourService.wsdl") but will also normally generate code like this in the static initializer of the class:

baseUrl = YourService.class.getResource(".");
url = new URL(baseUrl, "META-INF/wsdls/YourService.wsdl");

which will still point to a root folder to which it then adds the provided WSDL path to finally get a non existent path.

You will have to change the class after it's generated to include something like this instead:

url = YourService.class.getClassLoader().getResource("META-INF/wsdls/YourService.wsdl");

which will now point within the JAR. Off course you must pack the WSDL at that location when building the client JAR.

Bogdan
  • 23,890
  • 3
  • 69
  • 61