I have several WSDL files that I"m using to generate client code to talk to a remote service using SOAP. The generated code includes a line that looks like this:

public class AddProductService extends Service {

    static {
        URL url = null;
        try {
            url = new URL("file:/Users/developer/spg/spg-subman/SubscriptionManager/src/main/resources/wsdl/AddProduct.xml");

I've cut out some code that was generated and included only the line that I think is broken.

The WSDL files are in the project in src/main/resources/wsdl and that directory is not going to exist where this code will be deployed.

I'm using the cxf-codegen-plugin plugin with maven to generate this code.

I have a couple of questions:

  1. Is the WSDL required at runtime?
  2. If so, can I just copy it into the jar file and point the URL above to a classpath: URL?
  3. Can I copy the WSDL files into the target directory and then use those files to generate the java code for the client?

1 Answers

0
Tony Giaccone On

I'm answering this question because I found the answer and I've seen numerous people post code fragments that show the same problem I had, and in fact the cxf code examples demonstrates the same problem. Also I had multiple wsdlf files and how to solve that wasn't clear either.

The element that fixes this issue is:

  <wsdlLocation>AddProduct.xml</wsdlLocation>

The problem from my point of view is that tag wsdlLocation suggests a path, but this is not the entry for a path, you just put the wsdl file name here and at run time as long as you include the wsdl, in the class path of the jar file it will be found.

In the end the stanza in the pom for the configuration section of the cxf-codegen-plugin file looked like this:

<configuration>
    <sourceRoot>${project.build.directory}/generated-sources/cxf</sourceRoot>
    <wsdlOptions>
        <wsdlOption>
            <wsdl>${basedir}/src/main/resources/wsdl/AddProduct.xml</wsdl>
            <extraargs>
                <extraarg>-client</extraarg>
            </extraargs>
            <wsdlLocation>AddProduct.xml</wsdlLocation>
        </wsdlOption>
   </wsdlOptions>
</configuration

The result of this is that in the static declaration you end up with this:

URL url = AddProductService.class.getResource("AddProduct.xml");

and not this:

 url = new URL("file:/Users/tonyg/App/MyManager/src/main/resources/wsdl/AddProduct.xml");