Multiple WSDLs Configurations With Maven JAXWS
Asked Answered
P

2

14

I need to include more than one WSDL in my Maven JAXWS configuration and I need to specify different output directories for them since some of the method names in wsdlA conflict with method names in wsdlB. I'm using org.jvnet.jax-ws-commons and I need bindings to apply only to wsdlA, not wsdlB.

This is what I have at the moment:

<build>
    <pluginManagement>
      <plugins>
        <plugin> 
          <groupId>org.jvnet.jax-ws-commons</groupId> 
          <artifactId>jaxws-maven-plugin</artifactId> 
          <version>2.1</version> 
          <executions>
            <execution> 
              <goals> 
                <goal>wsimport</goal> 
              </goals>
            </execution> 
          </executions>
          <configuration> 
            <!-- Configure Output -->
            <packageName>com.mycee.project.model</packageName> 
            <sourceDestDir>src/main/java</sourceDestDir>
            <!-- Configure WSDL Location -->
            <wsdlFiles>
              <wsdlFile>
                ${basedir}/src/jaxws/wsdl/wsdla.wsdl
              </wsdlFile>
              <!--
              <wsdlFile> 
                ${basedir}/src/jaxws/wsdl/wsdlb.wsdl
              </wsdlFile>
              -->   
            </wsdlFiles>
            <!-- Configure Binding Location -->
            <bindingDirectory>
              ${basedir}/src/jaxws/binding
            </bindingDirectory>
            <!-- Make Output Verbose -->
            <verbose>true</verbose>
          </configuration> 
        </plugin>         
      </plugins>            
    </pluginManagement>
  </build>

UPDATED:

<build>
    <pluginManagement>
      <plugins>
          <!-- WSDL GENERATOR PLUGIN -->
          <!-- mvn jaxws:wsimport    -->
          <plugin> 
              <groupId>org.jvnet.jax-ws-commons</groupId> 
              <artifactId>jaxws-maven-plugin</artifactId> 
              <version>2.3</version> 
              <executions>
                  <!-- WSDL A -->
                  <execution>
                      <id>WSDLA</id>
                      <phase>generate-sources</phase>
                      <goals> 
                          <goal>wsimport</goal> 
                      </goals>
                      <configuration>
                          <packageName>com.mycee.project.model.wsdla</packageName>                                                                    <staleFile>${project.build.directory}/jaxws/stale/wsdl.a.done</staleFile>
                          <wsdlFiles>
                              <wsdlFile>${basedir}/src/jaxws/wsdl/wsdla.wsdl</wsdlFile>
                          </wsdlFiles>
                          <bindingDirectory>${basedir}/src/jaxws/binding</bindingDirectory>
                      </configuration>                          
                  </execution>
                  <!-- WSDL B -->
                  <execution>
                      <id>WSDLB</id>
                      <phase>generate-sources</phase>
                      <goals> 
                          <goal>wsimport</goal> 
                      </goals>
                      <configuration>        
                          <packageName>com.mycee.project.model.wsdlb</packageName>
                          <staleFile>${project.build.directory}/jaxws/stale/wsdl.b.done</staleFile>
                          <wsdlFiles>
                              <wsdlFile>${basedir}/src/jaxws/wsdl/wsdlb.wsdl</wsdlFile>
                          </wsdlFiles>
                      </configuration>
                  </execution>
              </executions>
              <!-- Common Config -->  
              <configuration>
                  <verbose>true</verbose>
                  <wsdlDirectory>
                      ${basedir}/src/jaxws/wsdl
                  </wsdlDirectory>
              </configuration>
          </plugin> 
      </plugins>  
    </pluginManagement>
  </build>

When running mvn clean jaxws:wsimport, I get the following notification with no java code being generated:

[INFO] --- jaxws-maven-plugin:2.2:wsimport (default-cli) @ [INFO] No WSDLs are found to process, Specify atleast one of the following parameters: wsdlFiles, wsdlDirectory or wsdlUrls.

Pyrrha answered 16/7, 2013 at 10:42 Comment(0)
D
25

The first thing is not to configure the configuration within the pluginManagement block. In this case it's better to define the version of the plugin only in the pluginManagement block. Furthermore to fulfill your requirement you need to have two executions like this:

   <plugin> 
    <groupId>org.jvnet.jax-ws-commons</groupId> 
    <artifactId>jaxws-maven-plugin</artifactId> 
    <executions>
        <execution> 
            <id>wsdla-exec</id>
            <goals> 
            <goal>wsimport</goal> 
            </goals>
            <configuration>
                <packageName>com.mycee.project.model</packageName> 
                <wsdlFiles>
                    <wsdlFile>${basedir}/src/jaxws/wsdl/wsdla.wsdl</wsdlFile>
                </wsdlFiles>
                <bindingDirectory>${basedir}/src/jaxws/binding</bindingDirectory>
                <verbose>true</verbose>
            </configuration>
        </execution> 
        <execution> 
            <id>wsdlb-exec</id>
            <goals> 
            <goal>wsimport</goal> 
            </goals>
            <configuration>
                <packageName>com.mycee.project.model</packageName> 
                <wsdlFiles>
                    <wsdlFile>${basedir}/src/jaxws/wsdl/wsdlb.wsdl</wsdlFile>
                </wsdlFiles>
                <bindingDirectory>${basedir}/src/jaxws/binding</bindingDirectory>
                <verbose>true</verbose>
            </configuration>
        </execution> 
    </executions>
</plugin>
Dippold answered 16/7, 2013 at 13:1 Comment(7)
I'm clearly missing something somewhere, I've created two execution blocks, both with <wsdlFiles><wsdlFile>...</wsdlFile></wsdlFiles>, running mvn clean jaxws:wsimport, I get the following notification: [INFO] --- jaxws-maven-plugin:2.2:wsimport (default-cli) @ ... --- [INFO] No WSDLs are found to process, Specify atleast one of the following parameters: wsdlFiles, wsdlDirectory or wsdlUrls.Pyrrha
Based on the docs you need to set wsdlDirectory cause you are not using the defaults (${basedir}/src/wsdl.).. Furthermore dont call a goal separatly better call the life cyclce like mvn generate-sources. Than you can see if the configuration etc. is ok. Afterwards use mvn package.Dippold
I've added it to the global config, then it picks up the WSDL files, but ignores the execution configurations, take it out and it once again asks for at least wsdlFiles, wsdlUrls or wsdlDirectory, any idea why my execution configurations are being ignored?Pyrrha
Neither mvn package nor mvn generate-sources are generating the java code.Pyrrha
Resolved by #17696173Pyrrha
You haven't read my post carefully, cause at start the information about pluginManagement has been mentioned.Dippold
A little side note - the correct goal to invoke maven seems to be mvn generate-sources and not mvn jaxws:wsimport for this answer.Puritanical
M
2

have an execution element for each wsdl and put the configuration within it. You can keep common configuration elements outside the execution element. e.g.:

<build>
<pluginManagement>
  <plugins>
    <plugin> 
      <groupId>org.jvnet.jax-ws-commons</groupId> 
      <artifactId>jaxws-maven-plugin</artifactId> 
      <version>2.1</version> 
      <executions>
        <execution>
          <id>wsdla</id>
          <goals> 
            <goal>wsimport</goal> 
          </goals>
          <configuration> 
             <wsdlFile>
               ${basedir}/src/jaxws/wsdl/wsdla.wsdl
             </wsdlFile>
             <sourceDestDir>target/gen/wsdla</sourceDestDir>
          </configuration> 
        </execution> 
        <execution>
          <id>wsdlb</id>
          <goals> 
            <goal>wsimport</goal> 
          </goals>
          <configuration> 
             <wsdlFile>
               ${basedir}/src/jaxws/wsdl/wsdlb.wsdl
             </wsdlFile>
             <sourceDestDir>target/gen/wsdlb</sourceDestDir>
          </configuration> 
        </execution> 
      </executions>
      <configuration> 
        <!-- Configure Output -->
        <packageName>com.mycee.project.model</packageName> 
        <!-- Configure Binding Location -->
        <bindingDirectory>
          ${basedir}/src/jaxws/binding
        </bindingDirectory>
        <!-- Make Output Verbose -->
        <verbose>true</verbose>
      </configuration> 
    </plugin>         
  </plugins>  

</pluginManagement>

Also, don't put generated code in /main/src/java as it won't get cleaned.

Murdocca answered 16/7, 2013 at 13:3 Comment(12)
I'm clearly missing something somewhere, I've created two execution blocks, both with <wsdlFiles><wsdlFile>...</wsdlFile></wsdlFiles>, running mvn clean jaxws:wsimport, I get the following notification: [INFO] --- jaxws-maven-plugin:2.2:wsimport (default-cli) @ ... --- [INFO] No WSDLs are found to process, Specify atleast one of the following parameters: wsdlFiles, wsdlDirectory or wsdlUrls.Pyrrha
did you specify <wsdlDirectory> in the global configuration section?Murdocca
For a moment there I thought that was working, but it was not. When I add wsdlDirectory to the global config, it picks up the WSDL files while still ignoring my execution configurations and then failing because one of the WSDLs uses a reserved JAVA keyword.Pyrrha
Any idea why maven or jaxws is ignoring my execution configurations?Pyrrha
remove <wsdlDirectory> from the execution configuration - it's only needed in the global configuration. Why do you also specify <wsdlUrl>? Which wsdl is wsimport going to use the one specified by <wsdlUrl> or <wsdlFile>?Murdocca
Doesn't matter what I put in the execution configuration, it can even be invalid, it doesn't get picked up. I've removed all the wsdlurls and extra wsdlDirectory, it still only picks up the global config, not the execution configs.Pyrrha
try adding the <staleFile> parameter in the execution configuration section - make sure each staleFile is unique per wsdl. Perhaps it's thinking it doesn't need to regenerate the sources from the wsdl. This should work - this is exactly the configuration we use.Murdocca
Have added stalefile to both of them, the double execution blocks only does something if I change the version to 2.3. Getting: [ERROR] Failed to execute goal org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.3:wsimport (default-cli) on project ...: Execution default-cli of goal org.jvnet.jax-ws-commons:jaxws-maven-plugin:2.3:wsimport failed: String index out of range: -1 -> [Help 1] Will post another topic for this.Pyrrha
let us continue this discussion in chatMurdocca
We use version 2.1. Actually we forked version 2.l and added the ability for XML schemas to be resolved across the classpath (thus across maven modules), but the rest of the plugin is the same.Murdocca
Saw your other thread - I can't believe I didn't notice you had all this in <pluginManagement> ... I'm glad you got your answer.Murdocca
I didn't know about this maven feature until yesterday, learning a lot from Stackoverflow :-)Pyrrha

© 2022 - 2024 — McMap. All rights reserved.