Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling JAX-WS wsdlLocation attribute value's (absolute path) with jaxws-maven-plugin

I have a JAX-WS-driven web service whose WSDL we generate a web service client from in another Maven module (which I'll call ws-consumer).

For better or worse, we copy the "published WSDLs" (the version of the WSDL & XSDs that the service held/generated at point of release) to our src/wsdl folder of ws-consumer and then use jaxws-maven-plugin from org.jvnet to generate a client using jaxws:wsimport with the following (truncated) configuration:

    <plugin>
        <groupId>org.jvnet.jax-ws-commons</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <version>2.1</version>
        <executions>
            <execution>
                <!--phase>generate-sources</phase -->
                <goals>
                    <goal>wsimport</goal>
                </goals>
                <configuration>
                    <wsdlDirectory>src/main/resources/META-INF/wsdl/</wsdlDirectory>
                    <wsdlFiles>
                        <wsdlFile>MyWS/MyWS.wsdl</wsdlFile>
                    </wsdlFiles>
                </configuration>
            </execution>
        </executions>
    </plugin>

Now, the generated client code has the following annotations applied at the class level:

@WebServiceClient(name = "MyWS", targetNamespace = "http://myws/blah", wsdlLocation = "**file:/C:/some/absolute/path/src/main/resources/META-INF/wsdl/MyWS/MyWS.wsdl"**)

emphasis mine

As you can hopefully see, the wsdlLocation attribute value has a hard-coded absolute path that is going to be incorrect when the service is deployed.

Is there any way I can "control" this by setting it to just META-INF/wsdl/MyWS/MyWS.wsdl or some other value?

like image 662
Alex Avatar asked Mar 21 '12 10:03

Alex


3 Answers

It is possible with the Codehaus plugin:

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>jaxws-maven-plugin</artifactId>
   <version>1.9</version>
   <executions>
     <execution>
       <goals>
         <goal>wsimport</goal>
       </goals>
     </execution>
   </executions>
   <configuration>
     <keep>true</keep>
     <verbose>true</verbose>
     <wsdlDirectory>../wscontract/src/main/resources/wsdl</wsdlDirectory>
     <wsdlLocation>wsdl/MaintainAddress.wsdl</wsdlLocation>
     <sourceDestDir>src/main/java</sourceDestDir>
     <bindingDirectory>.</bindingDirectory>
     <bindingFiles>
       <bindingFile>jaxb/xsdbindings.xml</bindingFile>
       <bindingFile>jaxb/wsdlbindings.xml</bindingFile>
     </bindingFiles>
   </configuration>
</plugin>

Perhaps the plugin you are using has a similar option or perhaps you can consider switching.

You can also provision your WSDL explicitly, in which case this property is ignored, though that may not be appropriate in a container-managed application.

Sample code here.

like image 82
McDowell Avatar answered Nov 15 '22 23:11

McDowell


Use wsdlLocation with the jaxws-maven-plugin from org.jvnet.jax-ws-commons:

<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
    <execution>
        <goals>
            <goal>wsimport</goal>
        </goals>
    </execution>
</executions>
<configuration>
    <wsdlDirectory>src/main/resources/wsdl</wsdlDirectory>
    <wsdlFiles>
        <wsdlFile>arsdev.wsdl</wsdlFile>
    </wsdlFiles>
    <wsdlLocation>wsdl/*</wsdlLocation>
    <!-- Keep generated files -->
    <keep>true</keep>
    <packageName>jaxws.remedy.client.generated</packageName>
    <!-- generated source files destination -->
    <sourceDestDir>target/generated-code/src</sourceDestDir>
</configuration>
</plugin>
like image 20
Dean Schulze Avatar answered Nov 16 '22 01:11

Dean Schulze


I voted up for @dean-schulze answer, as it's appropriate for the case of org.jvnet.jax-ws-commons:jaxws-maven-plugin plugin.

It may also be interesting to display help locally with CLI, like this :

mvn jaxws:help -Dgoal=wsimport -Ddetail

As said in the previous answer, we can use the wsdlLocation parameter, described here :

wsdlLocation
  @WebService.wsdlLocation and @WebServiceClient.wsdlLocation value.
  Can end with asterisk in which case relative path of the WSDL will be
  appended to the given wsdlLocation.

  Example:

   ...
   <configuration>
   <wsdlDirectory>src/mywsdls</wsdlDirectory>
   <wsdlFiles>
   <wsdlFile>a.wsdl</wsdlFile>
   <wsdlFile>b/b.wsdl</wsdlFile>
   <wsdlFile>${basedir}/src/mywsdls/c.wsdl</wsdlFile>
   </wsdlFiles>
   <wsdlLocation>http://example.com/mywebservices/*</wsdlLocation>
   </configuration>
   ...
  wsdlLocation for a.wsdl will be http://example.com/mywebservices/a.wsdl
  wsdlLocation for b/b.wsdl will be
  http://example.com/mywebservices/b/b.wsdl
  wsdlLocation for ${basedir}/src/mywsdls/c.wsdl will be
  file://absolute/path/to/c.wsdl


  Note: External binding files cannot be used if asterisk notation is in
  place.

The -wsdllocation option is also documented on the wsimport command from the JDK :

  • JDK 7 - wsimport
  • JDK 8 - wsimport

But it just says (see @WebServiceClient javadoc) :

Specifies the @WebServiceClient.wsdlLocation value.
like image 1
Guillaume Husta Avatar answered Nov 15 '22 23:11

Guillaume Husta