Bundling wsdl in jar with CXF wsdl2java

Andre Azzolini picture Andre Azzolini · Feb 23, 2011 · Viewed 9.7k times · Source

I'm working on an implementation that will use a wsdl that I have gotten from a vendor. Our project is running on Spring and CXF, and I'd like to create a jar that will allow me to access this vendor's wsdl services, but I'm running into classpath issues.

Using CXF's wsdl2java I am able to generate code that acts like this:

WSDL_LOCATION = new URL("file:SomeService.wsdl");

The service requires the wsdl to be in the classpath, but I would like to bundle it in the jar so that it is distributable as a stand-alone jar. Using the wsdl2java tool, I am able to specify the string in the URL instantiation to whatever I would like. However, I have not found a combination of a custom string and wsdl file location inside the jar that works.

The only way I have gotten this to work as I want is to put the wsdl file in the same folder that the SomeService.class is and use the following line:

WSDL_LOCATION = TrackService.class.getResource("TrackService_v4.wsdl");

However, this has the downside of me having to manually edit the java code and compile it myself. This is undesirable because we would eventually like to make this process part of our maven build and have wsdl2java do the generation and compilation by itself automatically.

I am OK with the wsdl being anywhere in the jar, but I don't know what to pass in to wsdl2java to have it reference a file inside the jar.

Does anyone have any suggestions or experience doing this?

Answer

mtpettyp picture mtpettyp · Feb 25, 2011

I've run into the same issue - I've got the following workaround but I'm still searching for something cleaner.

  1. Keep your wsdls in src/main/resources/wsdl

  2. Do the following when you create your TrackService:

    URL wsdlUrl = TrackService.class.getResource( "/wsdl/TrackService_v4.wsdl" ); TrackService service = new TrackService( wsdlUrl );

The ideal solution would be to pass the location as a <wsdlLocation/> element into the CXF wsdl2java plugin. Then your client code could call the default constructor. However the stub code that is generated does not allow you to specify a wsdl file that is on the classpath.