使用Maven JAXWS的多个WSDL配置

时间:2013-07-16 10:42:58

标签: maven jax-ws

我需要在我的Maven JAXWS配置中包含多个WSDL,并且我需要为它们指定不同的输出目录,因为wsdlA中的某些方法名称与wsdlB中的方法名称冲突。我正在使用org.jvnet.jax-ws-commons,我需要绑定才能仅应用于wsdlA,而不是wsdlB。

这就是我现在所拥有的:

<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>

更新:

<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>

运行mvn clean jaxws:wsimport时,我收到以下通知,没有生成java代码:

  

[INFO] --- jaxws-maven-plugin:2.2:wsimport(default-cli)@   [INFO]未找到要处理的WSDL,指定   至少以下参数之一:wsdlFiles,wsdlDirectory或wsdlUrls。

2 个答案:

答案 0 :(得分:15)

首先,不要在pluginManagement块中配置配置。在这种情况下,最好只在pluginManagement块中定义插件的版本。此外,为了满足您的要求,您需要执行两次这样的执行:

   <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>

答案 1 :(得分:2)

为每个wsdl都有一个执行元素,并将配置放在其中。您可以将常用配置元素保留在执行元素之外。 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>

另外,不要将生成的代码放在/ main / src / java中,因为它不会被清除。