Bundle the WSDL in the jar using CXF WSDL 2java
I am developing an implementation that will use the WSDL I obtained from the vendor Our project is running on spring and CXF. I want to create a jar that allows me to access the vendor's WSDL service, but I encounter a classpath problem
Using CXF's wsdl2java, I can generate the following code:
WSDL_LOCATION = new URL("file:SomeService.wsdl");
The service requires WSDL in the classpath, but I want to bundle it in a jar so that it can be distributed as a separate jar Using the wsdl2java tool, I can specify the string in the URL instantiation as anything I want However, I did not find a combination of custom strings and WSDL file locations in jar
The only way I want it to work as I wish is to put the WSDL file in someservice Class and use the following line:
WSDL_LOCATION = TrackService.class.getResource("TrackService_v4.wsdl");
However, there is a disadvantage. I have to edit the Java code manually and compile it myself This is undesirable because we ultimately want to make this process part of the Maven build and let wsdl2 Java generate and compile automatically
I'm fine with the WSDL anywhere in the jar, but I don't know what to pass to WSDL 2java to make it reference the files in the jar
Does anyone have any advice or experience to do so?
Solution
You need to specify the classpath WSDL location as follows to generate a stub that uses classloader to load this WSDL as a classpath resource:
<plugin> <groupId>org.apache.cxf</groupId> <artifactId>cxf-codegen-plugin</artifactId> <version>2.4.3</version> <dependencies> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-bindings-soap</artifactId> <version>2.4.3</version> </dependency> </dependencies> <executions> <execution> <id>generate-sources</id> <phase>generate-sources</phase> <configuration> <sourceRoot>${project.build.directory}/generated-sources/cxf </sourceRoot> <wsdlOptions> <wsdlOption> <wsdl>${basedir}/yourWSDL.wsdl</wsdl> <extraargs> <extraarg>**-wsdlLocation**</extraarg> <extraarg>**classpath:yourWSDL.wsdl**</extraarg> </extraargs> </wsdlOption> </wsdlOptions> </configuration> <goals> <goal>wsdl2java</goal> </goals> </execution> </executions> </plugin>