Multiple WSDLs Configurations With Maven JAXWS

試著忘記壹切 提交于 2020-05-25 16:35:23

问题


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.


回答1:


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>



回答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.



来源:https://stackoverflow.com/questions/17674456/multiple-wsdls-configurations-with-maven-jaxws

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!