“wsimport”ing several WSDL files with Maven and avoiding the generation of wsdlLocation with full path related to the local filesystem
When we use wsimport to generate the WS client based on a specific WSDL file with maven, if we do not take the appropriate caution, the generated code will end up with a wsdlLocation containing a full path related to the filesystem where the project is built. This recipe tells you one way to avoid that, even if you have more than one WSDL file in your project
Basically, all we have to do is configure the execution of the wsimport goal with the specific definition of the wsdlLocation we want to be generated, and make sure that WSDL location points to the appropriate path:
... <build> <plugins> ... <plugin> <groupId>org.jvnet.jax-ws-commons</groupId> <artifactId>jaxws-maven-plugin</artifactId> <version>2.2.1</version> <executions> <execution> <id>Wsdl1</id> <goals> <goal>wsimport</goal> </goals> <configuration> <packageName>com.linkare.myproject.ws</packageName> <wsdlFiles> <wsdlFile>Wsdl1.wsdl</wsdlFile> </wsdlFiles> <wsdlLocation>https://someserver.com/Wsdl1?wsdl</wsdlLocation> </configuration> </execution> <execution> <id>Wsdl2</id> <goals> <goal>wsimport</goal> </goals> <configuration> <packageName>com.linkare.myproject.ws</packageName> <wsdlFiles> <wsdlFile>Wsdl2.wsdl</wsdlFile> </wsdlFiles> <wsdlLocation>https://anotherserver.com/Wsdl2?wsdl</wsdlLocation> </configuration> </execution> ... other WSDL file configurations, if necessary </executions> </plugin> </plugins> </build> ...
The thing I do not appreciate much in this technique is the need to specify multiple executions, one for each WSDL file, with each with its own wsdlLocation but this was the only way I managed to make this work properly.
With the definition of different executions, one for each WSDL file contained in the project, with its own configuration properties, namely the definition of the wsdlLocation to be used within the project, it is possible to generate a WS client from a WSDL file for a specific project using Maven, without the undesired full path to the local WSDL file.