10

我需要在我的 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。

4

2 回答 2

17

首先不要在 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>
于 2013-07-16T13:01:24.157 回答
2

每个 wsdl 都有一个执行元素并将配置放入其中。您可以将通用配置元素保留在执行元素之外。例如:

<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 中,因为它不会被清理。

于 2013-07-16T13:03:35.517 回答